#include<iostream>
#include<cstdio>
using namespace std;
int t,n,a[2050][2050],maxx[10],minn[10],pm[2050][10],ji[10],ans[10];
char x;
int ab(int m){
	return m>0? m:-m;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(int i=0;i<=9;i++){
			ji[i]=0;
			maxx[i]=-1;
			minn[i]=2001;
			ans[i]=-1;
		}
		for(int i=1;i<=n;i++)
		  for(int j=1;j<=n;j++){
		  	x=getchar();
		  	while(x<'0'||x>'9')x=getchar();
		  	a[i][j]=x-'0';
		  	if(ji[a[i][j]]<2)ji[a[i][j]]++;
		  }
		for(int i=1;i<=n;i++)
		  for(int j=0;j<=9;j++)
		    pm[i][j]=-1;
		for(int i=1;i<=n;i++)
		  for(int j=1;j<=n;j++){
		  	maxx[a[i][j]]=max(maxx[a[i][j]],i);
		  	minn[a[i][j]]=min(minn[a[i][j]],i);
		  	pm[i][a[i][j]]=max(pm[i][a[i][j]],n-j);
		  	pm[i][a[i][j]]=max(pm[i][a[i][j]],j-1);
		  }
		for(int i=0;i<=9;i++)
		  if(ji[i]>1)
			for(int j=1;j<=n;j++)
			  if(pm[j][i]>=0){
				ans[i]=max(ans[i],(maxx[i]-j)*pm[j][i]);
				ans[i]=max(ans[i],(j-minn[i])*pm[j][i]);
			  }
		for(int i=1;i<=n;i++)
		  for(int j=0;j<=9;j++)
		    pm[i][j]=-1;
		for(int i=0;i<=9;i++){
			maxx[i]=-1;
			minn[i]=2001;
		}
		for(int i=1;i<=n;i++)
		  for(int j=1;j<=n;j++){
		  	maxx[a[j][i]]=max(maxx[a[j][i]],i);
		  	minn[a[j][i]]=min(minn[a[j][i]],i);
		  	pm[i][a[j][i]]=max(pm[i][a[j][i]],n-j);
		  	pm[i][a[j][i]]=max(pm[i][a[j][i]],j-1);
		  }
		for(int i=0;i<=9;i++)
		  if(ji[i]>1)
			for(int j=1;j<=n;j++)
			  if(pm[j][i]>=0){
				ans[i]=max(ans[i],(maxx[i]-j)*pm[j][i]);
				ans[i]=max(ans[i],(j-minn[i])*pm[j][i]);
			  }
		for(int i=0;i<=9;i++){
			if(ji[i]<=1)printf("0");
			else printf("%d",ans[i]);
			if(i<9)printf(" ");
		}
		printf("\n");
	}
	return 0;
}