#include<bits/stdc++.h>
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int t,n,c;
	string vec;
	cin>>t;
	while(t)
	{
		t-=1;
		cin>>n;
		std::vector<int> v;
		map <int,deque<pair<int,int>>> m;
		v.reserve(((long int)n)*n);
		int i,j;
		for(i=0;i<n;i++)
		{
			cin>>vec;
			for(j=0;j<n;j++)
			{
				//cin>>c;
				c=vec[j];
				c=c-48;
				//c=c%10;
				v.push_back(c);
				m[c].push_back(pair<int,int>(i,j));

			}
		}
		map <int,deque<int>> mr;
		map <int,deque<int>> mc;
		for(int i=0;i<10;i++)
		{
			int maxr=0;
			int minr=n;
			int maxc=0;
			int minc=n;
			for(auto j:m[i])
			{
				if(j.first>maxr)
					maxr=j.first;
				if(j.first<minr)
					minr=j.first;
				if(j.second>maxc)
					maxc=j.second;
				if(j.second<minc)
					minc=j.second;
			}
			mr[i].push_back(maxr);
			mr[i].push_back(minr);
			mc[i].push_back(maxc);
			mc[i].push_back(minc);
		}
		for(int i=0;i<10;i++)
		{
			int s=m[i].size(),a=0,ma1=0,ma2=0;
			for(j=0;j<s;j++)
			{
				ma1=max(m[i][j].first,n-1-m[i][j].first)*max(m[i][j].second-mc[i][1],mc[i][0]-m[i][j].second);
				ma2=max(m[i][j].second,n-1-m[i][j].second)*max(m[i][j].first-mr[i][1],mr[i][0]-m[i][j].first);
				a=max(ma1,max(a,ma2));
			}
			cout<<a<<" ";
		}
		cout<<endl;
	}
}