/*
 * yaswanth phani kommineni
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';

void solve(){
	ll n;
	cin >> n;
	vector < vector < vector <ll> > > pos(10,vector < vector <ll> >(n));
	vector < vector < vector <ll> > > pos1(10,vector < vector <ll> >(n));
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			char d;
			cin >> d;
			pos[d-'0'][i].push_back(j);
			pos1[d-'0'][j].push_back(i);
		}
	}
	vector <ll> ans(10,0);
	for(ll k=0;k<10;k++){
		for(ll i=0;i<n;i++){
			for(ll j=0;j<n;j++){
				if(!pos[k][i].empty() && !pos[k][j].empty()){
					ans[k] = max(ans[k],abs(i-j)*abs(pos[k][i].front()-pos[k][j].back()));
					ll t = max(i,n-i-1);
					t = max(t,j);
					t = max(t,n-j-1);
					ans[k] = max(ans[k],t*abs(pos[k][i].front()-pos[k][j].back()));
				}
				if(!pos1[k][i].empty() && !pos1[k][j].empty()){
					ans[k] = max(ans[k],abs(i-j)*abs(pos1[k][i].front()-pos1[k][j].back()));
					ll t = max(i,n-i-1);
					t = max(t,j);
					t = max(t,n-j-1);
					ans[k] = max(ans[k],t*abs(pos1[k][i].front()-pos1[k][j].back()));
				}
				
			}
		}
		cout << ans[k] << " ";
	}
	cout << endl;
}

int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc;
	tc = 1;
	cin >> tc;
	for(int i=1;i<=tc;i++){
		solve();
	}
	return 0;
}
