#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define llu unsigned long long
#define PB push_back
#define F first
#define S second
#define sz(a) ((ll)a.size())
const ll MOD = 1000000007;
const ll INF = 1000000000000000007;
#ifdef ONLINE_JUDGE
#define ck(x...)
#endif

void AC_aaega(){
	ll n;
	cin>>n;
	vector < vector < ll > > vv(n, vector < ll >(n, 0));
	vector < ll > k1(10, INF);
	vector < ll > k2(10, -1);
	vector < ll > q1(10, INF);
	vector < ll > q2(10, -1);
	for(ll i =0;i<n;i++){
		string s;
		cin>>s;
		for(ll j= 0;j<n;j++){
			vv[i][j] = s[j] - '0';
			k1[vv[i][j]] = min(k1[vv[i][j]], j);
			k2[vv[i][j]] = max(k2[vv[i][j]], j);
			q1[vv[i][j]] = min(q1[vv[i][j]], i);
			q2[vv[i][j]] = max(q2[vv[i][j]], i);
		}
	}	
	ck(k1, k2, q1, q2);
	for(ll i= 0;i<10;i++){
		ll ans =0, ff =-1, ss = -1;
		for(ll j =0;j<n;j++){
			for(ll k =0;k<n;k++){
				if(vv[j][k] == i){
					if(ff == -1){
						ff = k;
					}
					else{
						ss = k;
					}
				}
			}
			if(ss != -1 && ff != -1){
				ans = max(ans, (ss - ff) * max(j, n - 1 - j));
				ck(j, ss, ff);
			}
			if(ff != -1){
				ll qw = q1[i], wq = q2[i];
				if(qw != INF && wq != -1){
					ans = max(ans, max(abs(n-1-ff), ff) * max(j - qw, wq - j));
				}
				// else if(qw != -1){
				// 	ans = max(ans, max(abs(n-1-ff), ff) * j-qw);
				// }
			}
			if(ss != -1){
				ll qw = q1[i], wq = q2[i];
				if(qw != INF && wq != -1){
					ans = max(ans, max(abs(n-1-ss), ss) * max(j - qw, wq - j));
				}
				// else if(qw != -1){
				// 	ans = max(ans, max(abs(n-1-ff), ff) * j-qw);
				// }
			}
			ff = ss = -1;
		}
		ck(ans);
		for(ll j =0;j<n;j++){
			for(ll k =0;k<n;k++){
				if(vv[k][j] == i){
					if(ff == -1){
						ff = k;
					}
					else{
						ss = k;
					}
				}
			}
			if(ss != -1 && ff != -1){
				ans = max(ans, (ss - ff) * max(j, n - 1 - j));
			}
			if(ff != -1){
				ll qw = k1[i], wq = k2[i];
				if(qw != INF && wq != -1){
					ans = max(ans, max(abs(n-1-ff), ff) * max(j - qw, wq - j));
				}
				ck(ff, qw, wq);
				// else if(qw != -1){
				// 	ans = max(ans, max(abs(n-1-ff), ff) * j-qw);
				// }
			}
			if(ss != -1){
				ll qw = k1[i], wq = k2[i];
				if(qw != INF && wq != -1){
					ans = max(ans, max(abs(n-1-ss), ss) * max(j - qw, wq - j));
				}
				ck(ss, qw, wq);
				// else if(qw != -1){
				// 	ans = max(ans, max(abs(n-1-ff), ff) * j-qw);
				// }
			}
			ff = ss = -1;
		}
		cout<<ans<<' ';
	}
	cout<<'\n';
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	#ifndef ONLINE_JUDGE
			freopen("/home/theviralv/Desktop/input.txt", "r", stdin);
			freopen("/home/theviralv/Desktop/output.txt", "w", stdout);
			freopen("/home/theviralv/Desktop/err.txt", "w", stderr);
	#endif
	ll testcases = 1;
	cin>>testcases;
	while(testcases--){
		AC_aaega();
	}			
	return 0;
}