#include <stdio.h>
#include <ctype.h>
#include <string.h>
char grid[60][60];
char word[60];
int direct[8][2] = {
0, 1,
0, -1,
1, 0,
-1, 0,
1, 1,
-1, -1,
1, -1,
-1, 1,
};
void search(char *word, int m, int n)
{
int i, j;
int len = strlen(word);
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
{
int k;
for (k = 0; k < 8; k++)
{
int l;
int cur_x;
int cur_y;
for (l = 0; l < len; l++)
{
cur_x = i + l * direct[k][0];
cur_y = j + l * direct[k][1];
if (cur_x < 0 ||
cur_x >= m ||
cur_y < 0 ||
cur_y >= n ||
grid[cur_x][cur_y] != word[l])
break;
}
if (l == len)
{
printf("%d %d/n", i+1, j+1);
return;
}
}
}
}
void str_tolower(char *s)
{
int len = strlen(s);
int i;
for (i = 0; i < len; i++)
s[i] = tolower(s[i]);
}
int main()
{
int times;
int m, n;
scanf("%d", ×);
int i;
for (i = 0; i < times; i++)
{
if (i > 0)
printf("/n");
scanf("%d%d", &m, &n);
int j;
for (j = 0; j < m; j++)
{
scanf("%s", grid[j]);
str_tolower(grid[j]);
}
int nwords;
scanf("%d", &nwords);
for (j = 0; j < nwords; j++)
{
scanf("%s", word);
str_tolower(word);
search(word, m, n);
}
}
return 0;
}