1 #include<iostream>
2 #include<cstring>
3 using namespace std;
4
5 int head[101];
6 int cnt;
7
8 struct Edge
9 {
10 int u, next;
11 }e[10010];
12
13 void add(int u, int v)
14 {
15 e[++cnt].u = v;
16 e[cnt].next = head[u];
17 head[u] = cnt;
18 }
19
20 int n;
21 bool sc[51];
22 bool ho[51];
23 bool vis[51];
24 int match[51];
25
26 bool dfs(int x)
27 {
28 for (int i = head[x]; i != -1; i = e[i].next)
29 {
30 if (!vis[e[i].u])
31 {
32 vis[e[i].u] = true;
33 if (!match[e[i].u] || dfs(match[e[i].u]))
34 {
35 match[e[i].u] = x;
36 return true;
37 }
38 }
39 }
40 return false;
41 }
42
43 int T;
44 int tot;
45
46 int main()
47 {
48 cin >> T;
49 while (T--)
50 {
51 memset(head, -1, sizeof(head));
52 cnt = 0;
53 tot = 0;
54 cin >> n;
55 for (int i = 1; i <= n; i++)
56 {
57 cin >> sc[i];
58 }
59 for (int i = 1; i <= n; i++)
60 {
61 cin >> ho[i];
62 if (!ho[i] && sc[i])
63 {
64 add(i, i);
65 }
66 }
67 for (int i = 1; i <= n; i++)
68 {
69 if (!sc[i] || !ho[i] && sc[i]) tot++;
70 }
71 for (int i = 1; i <= n; ++i)
72 {
73 for (int j = 1; j <= n; ++j)
74 {
75 int t;
76 cin >> t;
77 if (t && sc[j]) add(i, j);
78 }
79 }
80 memset(match, 0, sizeof(match));
81 int cnt = 0;
82 for (int i = 1; i <= n; i++)
83 {
84 if (sc[i] && !ho[i] || !sc[i])
85 {
86 memset(vis, false, sizeof(vis));
87 if (dfs(i)) cnt++;
88 }
89 }
90 if (cnt == tot) cout << "^_^" << endl;
91 else cout << "T_T" << endl;
92 }
93 }