#include<cstdio>
#include<cstring>
const int N=210;
int map[N][N];
int book[N],ans[N];
int n;
bool find(int x)
{
for(int i=1;i<=n;i++)
{
if(map[x][i]&&(!book[i]))
{
book[i]=1;
if(!ans[i]||find(ans[i]))
{
ans[i]=x;
return true;
}
}
}
return false;
}
inline bool work()
{
for(int i=1;i<=n;i++)
{
memset(book,0,sizeof(book));
if(!find(i)) return 0;
}
return 1;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(map,0,sizeof(map));
memset(ans,0,sizeof(ans));
int x;
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
scanf("%d",&x);
if(x) map[i][j]=1;
}
if(work()) printf("Yes\n");
else printf("No\n");
}
return 0;
}