#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
int a[205][205];
const int maxn = 1e5+5;
int head[maxn*2], num, path[205], vis[205];
struct node
{
int to, nextt;
}e[maxn*2];
void add(int u, int v) {
e[num].to = v, e[num].nextt = head[u], head[u] = num++;
}
void init() {
num = 0;
mem1(head);
}
int dfs(int u) {
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(vis[v])
continue;
vis[v] = 1;
if(path[v] == -1 || dfs(path[v])) {
path[v] = u;
return 1;
}
}
return 0;
}
int main()
{
int t, n;
cin>>t;
while(t--) {
cin>>n;
init();
int cnt = 0;
for(int i = 0; i<n; i++) {
for(int j = 0; j<n; j++) {
scanf("%d", &a[i][j]);
if(a[i][j]) {
add(i+1, j+1);
}
}
}
mem1(path);
int flag = 0;
for(int i = 1; i<=n; i++) {
mem(vis);
if(!dfs(i))
flag = 1;
}
if(!flag) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}