#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=55;
int t,n,g[N][N],vis[N],p[N];
bool zx[N],hui[N],xu[N],ren,f;
bool dfs(int x,int s){
if(vis[x]==s) return 0;
vis[x]=s;
for(int i=1;i<=g[x][0];i++){
int y=g[x][i];
if(!zx[y]) continue;
if(p[y]==0||dfs(p[y],s)){
p[y]=x; return 1;
}
}
return 0;
}
int main(){
scanf("%d",&t);
while(t--){
memset(g,0,sizeof(g));f=0;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&zx[i]);
for(int i=1;i<=n;i++){
scanf("%d",&hui[i]);
if(!zx[i]) hui[i]=0;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
scanf("%d",&ren);
if(ren||i==j) g[i][++g[i][0]]=j;g[j][++g[j][0]]=i;
}
}
for(int i=1;i<=n;i++){
if(!hui[i]){
if(!dfs(i,i)){
f=1;puts("T_T");break;
}
}
}
if(!f) puts("^_^");
}
return 0;
}