暴力出奇迹。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool k[1005][1005];
int cx[1000005],cy[1000005],n,m,a,b;
int main()
{
int t;
cin>>t;
while(t--)
{
bool ak=1;
scanf("%d%d%d%d",&n,&m,&a,&b);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
char c=getchar();
while(c!='x'&&c!='.')
c=getchar();
if(c=='x')
k[i][j]=1;
else k[i][j]=0;
}
}
int flag=0;
/*for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
printf("%d ",k[i][j]);
printf("\n");
}*/
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
char c=getchar();
while(c!='x'&&c!='.')
c=getchar();
if(c=='x')
{
cx[++flag]=i;
cy[flag]=j;
}
}
}
if(!flag)
{
printf("NIE\n");
ak=0;
continue;
}
int tempx=cx[1],tempy=cy[1];
for(int i=1;i<=flag;i++)
{
cx[i]-=tempx;
cy[i]-=tempy;
}
bool ac=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(k[i][j])
{
//cout<<i<<" "<<j<<endl;
ac=1;
for(int l=1;l<=flag;l++)
{
tempx=i+cx[l];
tempy=j+cy[l];
if(tempx>n||tempy>m||!k[tempx][tempy])
{
ac=0;
printf("NIE\n");
break;
}
k[tempx][tempy]=0;
}
if(!ac)
{
break;
}
}
}
if(!ac)
{
break;
}
}
if(!ac)
continue;
printf("TAK\n");
}
}