#include <stdio.h> #include <string.h> char grid[100][52], word[20][100]; int xs[8]={-1,1,0,0,-1,-1,1,1}, ys[8]={0,0,-1,1,-1,1,-1,1};/*上、下、左、右、左上、右上、左下、右下*/ /*location结构体,包含坐标*/ typedef struct { int x, y; }location; /*find函数,返回首个匹配字符的位置*/ location find(char *wd, int m, int n) { location l; int i, j, k, x, y, count, len = strlen(wd); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { for(k = 0;k < 8;k++) { x = i; y = j; count = 0; if(grid[x][y] != wd[count]) break; while(count < len && grid[x][y] != '0') { if(grid[x][y] != wd[count]) break; else { x = x + xs[k]; y = y + ys[k]; count++; } } if(count == len) { l.x = i; l.y = j; return l; } } } } } int main() { int s, m, n, j; scanf("%d", &s); while(s--)/*程序主体:先统一(全变为小写字母),再比较*/ { int i , k; location l; memset(grid,'0',sizeof(grid)); memset(word,'0',sizeof(word)); scanf("%d%d",&m,&n); for(i = 1;i <= m;i++) scanf("%s", grid[i]+1); for(i = 1;i <= m;i++) for(k = 1;k <= n;k++) if(grid[i][k] >= 65 && grid[i][k] <= 90) grid[i][k] = grid[i][k] + 32; scanf("%d", &j); for(i = 0;i < j;i++) { k = 0; scanf("%s", word[i]); while(word[i][k]!='\0') { if(word[i][k] >= 65 && word[i][k] <= 90) word[i][k] = word[i][k] + 32; k++; } l = find(word[i], m, n); printf("%d %d\n", l.x, l.y); } if(s) printf("\n"); } return 0; }