#include <bits/stdc++.h>
using namespace std;
const int N=200+5;
struct sdf{
int to,next;
}eg[4*N*N];
int head[2*N],ne=0;
void add(int x,int y){
eg[++ne]={y,head[x]};
head[x]=ne;return ;
}
int n;
int a[N][N],m[2*N];
bool vis[2*N];
bool match(int pt){
for (int i=head[pt];i!=0;i=eg[i].next){
int v=eg[i].to;
if (vis[v])continue;
vis[v]=1;
if (!m[v]||match(m[v])){
m[v]=pt;return 1;
}
}return 0;
}
int main(){
freopen ("qmatrix.in","r",stdin);
freopen ("qmatrix.out","w",stdout);
int T;scanf("%d",&T);
while(T--){
memset(head,0,sizeof(head));ne=0;
memset(m,0,sizeof(m));
scanf("%d",&n);
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
scanf("%d",&a[i][j]);
if (a[i][j])add(i,j+n);
}
}int ans=0;
for (int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
if (match(i))ans++;
}
if (ans==n)printf("Yes\n");
else printf("No\n");
}
}