#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vl;
typedef pair<int,int> pint;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
string s[2005];
int firstRow[10][2005],firstColumn[10][2005],lastRow[10][2005],lastColumn[10][2005],maxRow[10],maxColumn[10],minRow[10],minColumn[10];
int main() 
{
 
    #ifndef ONLINE_JUDGE
	freopen("D:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("D:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=0;i<n;i++)
			cin>>s[i];
		for(int i=0;i<=9;i++)
		{
			for(int j=0;j<n;j++)
			{
				firstRow[i][j]=-1;
				lastRow[i][j]=-1;
				firstColumn[i][j]=-1;
				lastColumn[i][j]=-1;
			}
			maxRow[i]=-1;
			maxColumn[i]=-1;
			minRow[i]=-1;
			minColumn[i]=-1;
		}
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(firstRow[s[i][j]-48][i]==-1)
				{
					firstRow[s[i][j]-48][i]=j;
				}
				if(minRow[s[i][j]-48]==-1)
				{
					minRow[s[i][j]-48]=i;
				}
				lastRow[s[i][j]-48][i]=j;
				maxRow[s[i][j]-48]=i;
			}
		}
		for(int j=0;j<n;j++)
		{
			for(int i=0;i<n;i++)
			{
				if(firstColumn[s[i][j]-48][j]==-1)
				{
					firstColumn[s[i][j]-48][j]=i;
				}
				if(minColumn[s[i][j]-48]==-1)
				{
					minColumn[s[i][j]-48]=j;
				}
				lastColumn[s[i][j]-48][j]=i;
				maxColumn[s[i][j]-48]=j;
			}
		}
		vl ans(10,0);
		for(int i=0;i<=9;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(firstRow[i][j]==-1)
				{
					continue;
				}
				ans[i]=max(ans[i],max(n-1-firstRow[i][j],lastRow[i][j])*(maxRow[i]-j));
				ans[i]=max(ans[i],max(n-1-firstRow[i][j],lastRow[i][j])*(j-minRow[i]));
				if(firstRow[i][j]==lastRow[i][j])
				{
					continue;
				}
				ans[i]=max(ans[i],(lastRow[i][j]-firstRow[i][j])*max(j,n-1-j));
			}
		}
		for(int i=0;i<=9;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(firstColumn[i][j]==-1)
				{
					continue;
				}
				ans[i]=max(ans[i],max(n-1-firstColumn[i][j],lastColumn[i][j])*(maxColumn[i]-j));
				ans[i]=max(ans[i],max(n-1-firstColumn[i][j],lastColumn[i][j])*(j-minColumn[i]));
				if(firstColumn[i][j]==lastColumn[i][j])
				{
					continue;
				}
				ans[i]=max(ans[i],(lastColumn[i][j]-firstColumn[i][j])*max(j,n-1-j));
			}
		}
		for(int i=0;i<=9;i++)
			cout<<ans[i]<<" ";
		cout<<"\n";
	}
	return 0;
}