#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define down(i, l, r) for(int i = l; i >= r; i--)
#define MS 456
#define MAX 1037471823
#define Q 103
using namespace std;
int t, n, m[MS][MS], k[MS], a;
bool u[MS];
bool Find(int x)
{
rep(i, 1, n) if (m[x][i] == 1 && !u[i])
{
u[i] = 1;
if (k[i] == 0 || Find(k[i])) { k[i] = x; return true; }
}
return false;
}
int main()
{
scanf("%d", &t);
while (t-- > 0)
{
scanf("%d", &n);
rep(i, 1, n) rep(j, 1, n) scanf("%d", &m[i][j]);
rep(i, 1, n) k[i] = 0; a = 1;
while (a <= n)
{
memset(u, 0, sizeof(u));
if (Find(a)) a++; else break;
}
if (a <= n) printf("No\n"); else printf("Yes\n");
}
return 0;
}
I2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGZzdHJlYW0+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxxdWV1ZT4KCiNkZWZpbmUgcmVwKGksIGwsIHIpIGZvcihpbnQgaSA9IGw7IGkgPD0gcjsgaSsrKQojZGVmaW5lIGRvd24oaSwgbCwgcikgZm9yKGludCBpID0gbDsgaSA+PSByOyBpLS0pCiNkZWZpbmUgTVMgNDU2CiNkZWZpbmUgTUFYIDEwMzc0NzE4MjMKI2RlZmluZSBRIDEwMwoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCB0LCBuLCBtW01TXVtNU10sIGtbTVNdLCBhOwpib29sIHVbTVNdOwoKYm9vbCBGaW5kKGludCB4KQp7CglyZXAoaSwgMSwgbikgaWYgKG1beF1baV0gPT0gMSAmJiAhdVtpXSkKCXsKCQl1W2ldID0gMTsKCQlpZ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