#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 300
vector<int> V[MAXN];
int vis[MAXN];
int pat[MAXN];
int find(int x)
{
int i;
for (i=0;i<V[x].size();i++)
{
if (vis[V[x][i]])continue;
vis[V[x][i]]=true;
if (pat[V[x][i]]==-1||find(pat[V[x][i]]))
{
pat[V[x][i]]=x;
return 1;
}
}
return 0;
}
int main()
{
freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int nn,n,m;
int i,j,k;
int x;
int tot;
scanf("%d",&nn);
while (nn--)
{
scanf("%d",&n);
for (i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&x);
if (x)V[i].push_back(j);
}
}
tot=0;
memset(pat,-1,sizeof(pat));
for (i=0;i<n;i++)
{
memset(vis,0,sizeof(vis));
tot+=find(i);
}
if (tot==n)
{
printf("Yes\n");
}else
{
printf("No\n");
}
for(i=0;i<n;i++)V[i].clear();
}
}