#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-‘0‘;
return x*f;
}
const int maxn=210;
int n,e[maxn][maxn],left[maxn],vis[maxn];
int match(int x) {
rep(i,1,n) if(e[x][i]&&!vis[i]) {
vis[i]=1;
if(!left[i]||match(left[i])) {
left[i]=x;return 1;
}
}
return 0;
}
int main() {
int T=read();
while(T--) {
memset(left,0,sizeof(left));
memset(e,0,sizeof(e));
n=read();int ans=0;
rep(i,1,n) rep(j,1,n) e[i][j]=read();
rep(i,1,n) {
memset(vis,0,sizeof(vis));
if(match(i)) ans++;
}
puts(ans==n?"Yes":"No");
}
return 0;
}