RT,感觉写的没有问题
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<unordered_map>
#include<vector>
#include<queue>
#include<set>
#include<ctime>
#include<random>
#define x1 xx1
#define y1 yy1
#define IOS ios::sync_with_stdio(false)
#define ITIE cin.tie(0);
#define OTIE cout.tie(0);
#define PY puts("Yes")
#define PN puts("No")
#define popcount __builtin_popcount
#define pii pair<int,int>
#define mp make_pair
using namespace std;
inline int R(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}return x*f;
}
inline void write(int x){
if(x<0){x=-x;putchar('-');}
int y=0;char z[70];
while(x||!y){z[y++]=x%10+48;x/=10;}
while(y--)putchar(z[y]);
}
inline void writesp(int x){
write(x);putchar(32);
}
inline void writeln(int x){
write(x);putchar(10);
}
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define reprange(a,b,c,d) for(int a=b;a<=c;a+=d)
#define perrange(a,b,c,d) for(int a=b;a>=c;a-=d)
#define graph(i,j,k) for(int i=head[j];i;i=k[i].nxt)
const int maxn=405,maxm=1e5+5;
int n,a[maxn][maxn];
struct edge{
int to,nxt;
}e[maxm];
int head[maxn],edges;
void add(int x,int y){
e[++edges]=(edge){y,head[x]};
head[x]=edges;
}
int vis[maxn],match[maxn];
void init(){
memset(head,0,sizeof head);
memset(vis,0,sizeof vis);
memset(match,0,sizeof match);edges=0;
}
bool dfs(int x,int tag){
if(vis[x]==tag) return 0;
vis[x]=tag;
graph(i,x,e){
int u=e[i].to;
if(!match[u]||dfs(u,tag)){
match[u]=x,match[x]=u;
return 1;
}
}
return 0;
}
void solve(){
init();
n=R();rep(i,1,n)rep(j,1,n)a[i][j]=R();
rep(i,1,n)rep(j,1,n)if(a[i][j])add(i,j+n);
int ans=0;rep(i,1,n)if(dfs(i,i))ans++;
if(ans==n)PY;else PN;
}
int main(){
int _=R();while(_--)solve();
}