char s[maxn]; int n, m, a, b; int mtr[maxn][maxn], pa[maxn][maxn]; int needx[maxn * maxn], needy[maxn * maxn], deltx[maxn * maxn], delty[maxn * maxn]; int num_n, num_d; int sx, sy;
boolchk(int x, int y){ for (int i = 1; i <= num_d; ++i) { int ix = x + deltx[i], iy = y + delty[i]; if (ix < 1 || ix > n || iy < 1 || iy > m) return0; if (!mtr[ix][iy]) return0; mtr[ix][iy] = 0; } return1; }
intmain(){ int T; scanf("%d", &T); while (T--) { num_d = num_n = 0; scanf("%d%d%d%d", &n, &m, &a, &b); for (int i = 1; i <= n; ++i) { scanf("%s", s + 1); for (int j = 1; j <= m; ++j) { mtr[i][j] = (s[j] == 'x'); if (mtr[i][j]) { needx[++num_n] = i; needy[num_n] = j; } } } for (int i = 1; i <= a; ++i) { scanf("%s", s + 1); for (int j = 1; j <= b; ++j) { pa[i][j] = (s[j] == 'x'); if (pa[i][j]) { if (!num_d) { sx = i; sy = j; ++num_d; } else { deltx[++num_d] = i - sx; delty[num_d] = j - sy; } } } } bool sol = true; for (int i = 1; i <= num_n; ++i) if (mtr[needx[i]][needy[i]]) if (!chk(needx[i], needy[i])) { puts("NIE"); sol = false; break; } if (sol) puts("TAK"); } return0; }