#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2000005;

inline long long read(){
	long long k = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9'){k = k*10 + ch - '0'; ch = getchar();}
	return k * f;
}

long long a[MAXN];

int p[2005][2005];
int linemax[2005][10], colmax[2005][10];
int farline[10], farcol[10];
int ans[10];
int neacol[2005], nealine[2005];
char s[5000];

int main(){
	int t = read();
	for(int c = 1; c <= t; c++){
		memset(linemax, 0, sizeof(linemax));
		memset(colmax, 0, sizeof(colmax));
		memset(farline, 0, sizeof(farline));
		memset(farcol, 0, sizeof(farcol));
		memset(ans, 0, sizeof(ans));
		memset(neacol, 0x3f, sizeof(neacol));
		memset(nealine, 0x3f, sizeof(nealine));
		int n = read();
		for(int i = 1; i <= n; i++){
			scanf("%s", s + 1);
			for(int j = 1; j <= n; j++){
				p[i][j] = s[j] - '0';
			}
		}
		
		
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
//				printf("%d ", p[i][j]);
				linemax[i][p[i][j]] = max(linemax[i][p[i][j]], max(j, n - j + 1));
				farline[p[i][j]] = max(farline[p[i][j]], i);
				nealine[p[i][j]] = min(nealine[p[i][j]], i);
				colmax[j][p[i][j]] = max(colmax[j][p[i][j]], max(i, n - i + 1));
				farcol[p[i][j]] = max(farcol[p[i][j]], j);
				neacol[p[i][j]] = min(neacol[p[i][j]], j);
			}
//			printf("\n");
		}
		
//		for(int j = 0; j <= 9; j++){
//			for(int i = 1; i <= n; i++){
//				printf("linemax[%d][%d] = %d\n", i, j, linemax[i][j]);
//			}
//			for(int i = 1; i <= n; i++){
//				printf("colmax[%d][%d] = %d\n", i, j, colmax[i][j]);
//			}
//			printf("farline[%d] = %d\n", j, farline[j]);
//			printf("nealine[%d] = %d\n", j, nealine[j]);
//			printf("farcol[%d] = %d\n", j, farcol[j]);
//			printf("neacol[%d] = %d\n", j, neacol[j]);
//		}
		
		for(int j = 0; j <= 9; j++){
			for(int i = 1; i <= farline[j]; i++){
//				printf("linemax = %d, h = %d\n", linemax[i][j], farline[j] - i);
				ans[j] = max(ans[j], (linemax[i][j] - 1) * (farline[j] - i));
			}
		}
		for(int j = 0; j <= 9; j++){
			for(int i = 1; i <= farcol[j]; i++){
				if(j == 3){
//					printf("linemax = %d, h = %d\n", linemax[i][j], farline[j] - i);
				}
//				
				ans[j] = max(ans[j], (colmax[i][j] - 1) * (farcol[j] - i));
			}
		}
		
		for(int j = 0; j <= 9; j++){
			for(int i = nealine[j]; i <= n; i++){
				ans[j] = max(ans[j], (linemax[i][j] - 1) * (i - nealine[j]));
//				printf("linemax = %d, h = %d\n", linemax[i][j], farline[j] - i);
			}
		}
		for(int j = 0; j <= 9; j++){
			for(int i = neacol[j]; i <= n; i++){
				ans[j] = max(ans[j], (colmax[i][j] - 1) * (i - neacol[j]));
//				printf("linemax = %d, h = %d\n", linemax[i][j], farline[j] - i);
			}
		}
		
		for(int j = 0; j <= 9; j++){
			printf("%d ", ans[j]);
		}
		printf("\n");
	}
	return 0;
}


