# Bzoj3750 [poi2015]pieczęć

## 模拟不水题

Posted by yjjr's blog on November 26, 2018

# 题目

## Sample Input

2
3 4 4 2
xx..
.xx.
xx..
x.
.x
x.
..
2 2 2 2
xx
xx
.x
x.


## Sample Output

TAK
NIE


# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
using namespace std;
inline ll read(){
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
//******head by yjjr******
const int maxn=1e3+6;
struct node{int x,y;}s[maxn*maxn];
int n,m,a,b,cnt=0,T;bool flag;
char st[maxn][maxn],ch;
void check(int x,int y){
if(cnt==0)flag=0;
rep(i,1,cnt){
if(!flag)return;
int dx=x+s[i].x,dy=y+s[i].y;
if(dx<1||dx>n||dy<1||dy>m||st[dx][dy]=='.')flag=0;else st[dx][dy]='.';
}
}
inline bool JUD(){
n=read(),m=read(),a=read(),b=read();
rep(i,1,n)scanf("%s",st[i]+1);
rep(i,0,a-1)rep(j,0,b-1){cin>>ch;if(ch=='x')s[++cnt]=(node){i,j};}
dep(i,cnt,1)s[i].x-=s[1].x,s[i].y-=s[1].y;
flag=1;
rep(i,1,n)rep(j,1,m)if(st[i][j]=='x')check(i,j);
return flag;
}
int main(){
T=read();
while(T--){cnt=0;if(JUD())puts("TAK");else puts("NIE");}
return 0;
}