#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
int main() {
ll t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<vector<char> > v(n+1, vector<char>(n+1));
vector<int> sum(n+1, 0), ans(n, 0);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cin >> v[i][j];
if(v[i][j] == '1' && i > j || v[i][j] == '0' && i < j){
sum[i]++;
}
}
}
for(int i = 1; i <= n; i++){
ans[sum[i]] = i;
}
for(auto u: ans)cout << u << " ";
cout << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c2V0Pgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmludCBtYWluKCkgewogICAgbGwgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUodC0tKXsKICAgICAgICBpbnQgbjsKICAgICAgICBjaW4gPj4gbjsKICAgICAgICB2ZWN0b3I8dmVjdG9yPGNoYXI+ID4gdihuKzEsIHZlY3RvcjxjaGFyPihuKzEpKTsKICAgICAgICB2ZWN0b3I8aW50PiBzdW0obisxLCAwKSwgYW5zKG4sIDApOwogICAgICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKXsKICAgICAgICAgICAgZm9yKGludCBqID0gMTsgaiA8PSBuOyBqKyspewogICAgICAgICAgICAgICAgY2luID4+IHZbaV1bal07CiAgICAgICAgICAgICAgICBpZih2W2ldW2pdID09ICcxJyAmJiBpID4gaiB8fCB2W2ldW2pdID09ICcwJyAmJiBpIDwgail7CiAgICAgICAgICAgICAgICAJc3VtW2ldKys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspewogICAgICAgICAgIGFuc1tzdW1baV1dID0gaTsKICAgICAgICB9CiAgICAgICAgZm9yKGF1dG8gdTogYW5zKWNvdXQgPDwgdSA8PCAiICI7CiAgICAgICAgY291dCA8PCBlbmRsOwogICAgfQp9