// Arup Guha
// 8/1/2026
// Solution to 1989 UCF HS Programming Contest Problem: Word Search

import java.util.*;

public class word {

	// Directions words could be.
	final public static int[] DR = {-1,-1,-1,0,0,1,1,1};
	final public static int[] DC = {-1,0,1,-1,1,-1,0,1};
	
	public static int r;
	public static int c;
	public static char[][] g;
	
	public static void main(String[] args) {
	
		// Get size.
		Scanner stdin = new Scanner(System.in);
		r = stdin.nextInt();
		c = stdin.nextInt();
		
		// Read grid.
		g = new char[r][];
		for (int i=0; i<r; i++)
			g[i] = stdin.next().toCharArray();
			
		// Process each word.
		int nW = stdin.nextInt();
		for (int i=0; i<nW; i++) {
			char[] word = stdin.next().toCharArray();
			output(word);
		}
	}
	
	// Find and output for w. (guaranteed to be in the grid exactly once.)
	public static void output(char[] w) {
		
		// Try each starting cell.
		for (int i=0; i<r; i++) {
			for (int j=0; j<c; j++) {
			
				// Try each direction.
				for (int d=0; d<DR.length; d++) {
				
					// See if w appears in the grid starting at row i, col j in direction d.
					if (match(i,j,d,w)) {
						
						// Compute where the word ends.
						int endR = i + (w.length-1)*DR[d];
						int endC = j + (w.length-1)*DC[d];
						
						// Corresponding output.
						System.out.println(new String(w)+ " "+(i+1)+" "+(j+1)+" "+(endR+1)+" "+(endC+1));
					
						// Get out.
						return;
					}
				}
			}
		}
	}
	
	// Returns true iff w is in the grid starting at row sR, ending at column sC in
	// direction d.
	public static boolean match(int sR, int sC, int d, char[] w) {
		
		// Get this out of the way!
		int endR = sR + (w.length-1)*DR[d];
		int endC = sC + (w.length-1)*DC[d];
		if (!inbounds(endR, endC)) return false;
		
		// Go letter for letter.
		for (int i=0; i<w.length; i++) {
		
			// Not a match.
			if (g[sR][sC] != w[i]) return false;
			
			// Go next.
			sR += DR[d];
			sC += DC[d];
		}
		
		return true;	
	}
	
	// Returns true iff row x, column y is inbounds.
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < r && y >= 0 && y < c;
	}
}
		