1 /**************************************************************
2 Problem: 1059
3 User: Tunix
4 Language: C++
5 Result: Accepted
6 Time:108 ms
7 Memory:1620 kb
8 ****************************************************************/
9
10 //BZOJ 1059
11 #include<cstdio>
12 #include<cstring>
13 #include<cstdlib>
14 #include<iostream>
15 #include<algorithm>
16 #define rep(i,n) for(int i=0;i<n;++i)
17 #define F(i,j,n) for(int i=j;i<=n;++i)
18 #define D(i,j,n) for(int i=j;i>=n;--i)
19 #define pb push_back
20 using namespace std;
21 typedef long long LL;
22 inline int getint(){
23 int r=1,v=0; char ch=getchar();
24 for(;!isdigit(ch);ch=getchar()) if (ch==‘-‘) r=-1;
25 for(; isdigit(ch);ch=getchar()) v=v*10-‘0‘+ch;
26 return r*v;
27 }
28 const int N=210;
29 /*******************template********************/
30 int to[N*N],next[N*N],head[N],cnt;
31 void add(int x,int y){
32 to[++cnt]=y; next[cnt]=head[x]; head[x]=cnt;
33 }
34 int my[N],n;
35 bool vis[N];
36 bool dfs(int x){
37 for(int i=head[x];i;i=next[i])
38 if (!vis[to[i]]){
39 vis[to[i]]=1;
40 if (!my[to[i]] || dfs(my[to[i]]) ){
41 my[to[i]]=x;
42 return 1;
43 }
44 }
45 return 0;
46 }
47 int main(){
48 #ifndef ONLINE_JUDGE
49 freopen("1059.in","r",stdin);
50 freopen("1059.out","w",stdout);
51 #endif
52 int T=getint();
53 while(T--){
54 memset(head,0,sizeof head); cnt=0;
55 memset(my,0,sizeof my);
56 n=getint();
57 F(i,1,n) F(j,1,n){
58 int x=getint();
59 if (x) add(i,j);
60 }
61 int num=0;
62 F(i,1,n){
63 memset(vis,0,sizeof vis);
64 if (dfs(i)) num++;
65 }
66 if (num==n) puts("Yes");
67 else puts("No");
68 }
69 return 0;
70 }
71