#include<bits/stdc++.h>
using namespace std;
char s[3000][3000];
int l[3000],r[3000];
int main(){
	int t;
	scanf("%d",&t);
	while (t--){
		int n;
		scanf("%d",&n);
		for (int i=1;i<=n;i++)
			scanf("%s",s[i]+1);
		for (int i='0';i<='9';i++){
			for (int j=1;j<=n;j++){
				l[j]=n+1;
				r[j]=0;
				for (int k=1;k<=n;k++)
					if (s[j][k]==i){
						l[j]=min(l[j],k);
						r[j]=max(r[j],k);
					}
			}
			int ans=0;
			for (int j=1;j<=n;j++){
				if (!r[j]) continue;
				if (l[j]!=r[j]) ans=max(ans,max(j-1,n-j)*(r[j]-l[j]));
				for (int k=1;k<=n;k++)
					if (r[k]) ans=max(ans,max(n-l[j],r[j]-1)*abs(k-j));
			}
			for (int j=1;j<=n;j++){
				l[j]=n+1;
				r[j]=0;
				for (int k=1;k<=n;k++)
					if (s[k][j]==i){
						l[j]=min(l[j],k);
						r[j]=max(r[j],k);
					}
			}
			for (int j=1;j<=n;j++){
				if (!r[j]) continue;
				if (l[j]!=r[j]) ans=max(ans,max(j-1,n-j)*(r[j]-l[j]));
				for (int k=1;k<=n;k++)
					if (r[k]) ans=max(ans,max(n-l[j],r[j]-1)*abs(k-j));
			}
			printf("%d ",ans);
		}
		putchar('\n');
	}
	return 0;
}