#include<bits/stdc++.h>
#define LL long long
#define RG register
#define il inline
#define N 100010
using namespace std;
struct ed{int nxt,to,c;}e[N];
int head[N],tot,n,dep[N];
void link(int u,int v,int c){e[tot].nxt=head[u];e[tot].to=v;e[tot].c=c;head[u]=tot++;}
void LINK(int u,int v,int c){link(u,v,c),link(v,u,0);}
bool BFS(int s,int t){
memset(dep,0,sizeof(dep));
dep[s]=1;queue<int>que;while(!que.empty())que.pop();
que.push(s);
while(!que.empty()){
int u=que.front();que.pop();
for(int i=head[u];i!=-1;i=e[i].nxt)if(!dep[e[i].to]&&e[i].c){
int v=e[i].to;
dep[v]=dep[u]+1;
if(v==t)return true;
que.push(v);
}
}return false;
}
int dinic(int s,int t,int T){
if(s==t)return T;int tag(0);
for(int i=head[s];i!=-1;i=e[i].nxt)if(dep[s]+1==dep[e[i].to]&&e[i].c){
int d=dinic(e[i].to,t,min(T-tag,e[i].c));
e[i].c-=d,e[i^1].c+=d,tag+=d;
if(tag==T)break;
}if(!tag)dep[s]=0;return tag;
}
int maxflow(int s,int t){
int flow(0);
while(BFS(s,t))flow+=dinic(s,t,(1<<30));
return flow;
}
void clear(){tot=0;memset(head,-1,sizeof(head));}
int main(){
int T;scanf("%d",&T);
while(T--){
clear();
scanf("%d",&n);int kk;
for(int i=1;i<=n;++i)LINK(0,i,1),LINK(i+n,2*n+1,1);
for(int i=1;i<=n;++i)
for(int j=n+1;j<=2*n;++j){
scanf("%d",&kk);
if(kk)LINK(i,j,1);
}
if(maxflow(0,2*n+1)==n)cout<<"Yes\n";
else cout<<"No\n";
}
}