#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define OJ \
freopen("input.txt","r",stdin); \
freopen("output.txt","w",stdout);
int main()
{
//OJ;
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
int a[n][n];
for(int i=0;i<n;++i)
{
for(int j=0;j<n;++j)
{
cin>>a[i][j];
}
}
string ans="YES";
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1;j++)
{
if(a[i][j]==1&&a[i+1][j]==0&&a[i][j+1]==0)
{
ans="NO";
}
}
}
cout<<ans<<endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcgCiNkZWZpbmUgT0ogXAogICAgICAgIGZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKTsgXAogICAgICAgIGZyZW9wZW4oIm91dHB1dC50eHQiLCJ3IixzdGRvdXQpOwoKaW50IG1haW4oKQp7CiAgLy9PSjsKICAvLyBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAvLyBjaW4udGllKE5VTEwpOwogCmludCBUOwpjaW4+PlQ7CndoaWxlKFQtLSkKewogICAgaW50IG47CiAgICAKICAgIGNpbj4+bjsKICAgIGludCBhW25dW25dOwogICAgZm9yKGludCBpPTA7aTxuOysraSkKICAgIHsKICAgICAgICBmb3IoaW50IGo9MDtqPG47KytqKQogICAgICAgIHsKICAgICAgICAgICAgY2luPj5hW2ldW2pdOwogICAgICAgIH0KICAgIH0KICAgIHN0cmluZyBhbnM9IllFUyI7CiAgICBmb3IoaW50IGk9MDtpPG4tMTtpKyspCiAgICB7CiAgICAgICAgZm9yKGludCBqPTA7ajxuLTE7aisrKQogICAgICAgIHsKICAgICAgICAgICAgaWYoYVtpXVtqXT09MSYmYVtpKzFdW2pdPT0wJiZhW2ldW2orMV09PTApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGFucz0iTk8iOwogICAgICAgICAgICAgIAogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgY291dDw8YW5zPDxlbmRsOwogICAgCn0KfQ==