1. 
/**
* FWP: Ausgewaehlte Probleme aus dem ACM (SS10)
*
* Method: ad hoc (brute force)
* Problem: 10010 - Wheres Waldorf
* Accepted: 0.316
* @author Evgeni Pavlidis
*
*/

import java.io.*;
import java.util.*;

class Main {


private static char[][] grid;
private static int m,n,probes;

private static boolean check(String s, int y, int x)
{
int checkX, checkY;
int pos;
for(int dy=-1; dy <= 1; dy++)
for(int dx=-1; dx <= 1; dx++)
if(dy != 0 || dx != 0)
{
pos = 0;
checkY = y;
checkX = x;
do
{
pos++;
if(pos == s.length())
return true;
checkY += dy;
checkX += dx;
if(checkX < 0 || checkX >= n || checkY < 0 || checkY >= m)
break;

}while(s.charAt(pos) == grid[checkY][checkX]);
}


return false;
}

public static void main(String...args)
{
Scanner scanner = new Scanner(System.in);
int testCases = scanner.nextInt();

for(int c = 0; c < testCases; c++)
{
m = scanner.nextInt();
n = scanner.nextInt();
grid = new char[m][n];

for(int y=0; y < m; y++)
grid[y] = scanner.next().toLowerCase().toCharArray();


probes = scanner.nextInt();
String test;
for(int p = 0; p < probes; p++)
{
test = scanner.next().toLowerCase();
boolean b = false;
for(int y=0; y < m; y++)
for(int x=0; x < n; x++)
if(test.charAt(0) == grid[y][x])
if(check(test, y, x))
{
System.out.println((y+1) + " " + (x+1));
y = m;
x = n;
b = true;
}
if(!b)
throw new RuntimeException();

}

if(c < testCases-1)
System.out.println();

}
}
}