#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int t,S,T,n,a[55],b[55],cur[105],tot,h[105],dep[105],q[110];
struct edge{
int to,nxt,z;
}e[10000];
void add(int x,int y,int z)
{
e[++tot] = (edge){y,h[x],z},h[x] = tot;
e[++tot] = (edge){x,h[y],0},h[y] = tot;
}
int bfs()
{
for (int i = 0; i <= T; i++) cur[i] = h[i];
memset(dep,0,sizeof dep);
int head = 0,tail = 0;
q[++tail] = S,dep[S] = 1;
while (head < tail)
{
int u = q[++head];
for (int i = h[u]; i; i = e[i].nxt)
{
int v = e[i].to;
if (dep[v] || e[i].z <= 0) continue;
dep[v] = dep[u] + 1,q[++tail] = v;
}
}
if (dep[T]) return 1;
return 0;
}
int dinic(int u,int mn,int fa)
{
if (u == T || mn == 0) return mn;
int sum = 0,flow = 0;
for (int i = cur[u]; i; i = e[i].nxt)
{
cur[u] = i; int v = e[i].to;
if (v == fa || dep[v] != dep[u] + 1 || e[i].z <= 0) continue;
sum = dinic(v,min(mn,e[i].z),u);
if (sum <= 0) continue;
flow += sum,mn -= sum,e[i].z -= sum,e[i ^ 1].z += sum;
if (mn <= 0) break;
}
return flow;
}
int main()
{
scanf("%d",&t);
for (; t; t--)
{
memset(h,0,sizeof h),tot = 1;
scanf("%d",&n),S = n * 2 + 1,T = n * 2 + 2;
for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
for (int i = 1; i <= n; i++) scanf("%d",&b[i]);
for (int i = 1; i <= n; i++)
for (int j = 1,q1; j <= n; j++)
{
scanf("%d",&q1);
if ((!b[i] || !a[i]) && a[j] && q1) add(i,j + n,1);
}
for (int i = 1; i <= n; i++)
if (a[i] && !b[i]) add(i,i + n,1);
int res = 0,ans = 0;
for (int i = 1; i <= n; i++)
{
if (!b[i] || !a[i]) add(S,i,1),res++;
if (a[i]) add(i + n,T,1);
}
while (bfs()) ans += dinic(S,2147483647,S);
if (ans == res) printf("^_^\n");
else printf("T_T\n");
}
}