#include <bits/stdc++.h>
#define lowbit(i) ((i)&(-i))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MAXN = 2000 + 15;
char s[MAXN][MAXN];
int ans[15], li[15], ri[15], lj[15], rj[15];
int main() {
#ifdef CitricAcid
    freopen ("input.txt", "rt", stdin);
#endif
    
    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++) {
            li[i] = lj[i] = n;
            ri[i] = rj[i] = 0;
            ans[i] = 0;
        }

        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                int dig = s[i][j] - '0';
                li[dig] = min(li[dig], i);
                ri[dig] = max(ri[dig], i);
                lj[dig] = min(lj[dig], j);
                rj[dig] = max(rj[dig], j);
            }
        }

        for(int i = 1; i <= n; i++) {
            for(int j = 1; j <= n; j++) {
                int dig = s[i][j] - '0';
                ans[dig] = max(ans[dig], abs(li[dig] - i) * max(j - 1, n - j));
                ans[dig] = max(ans[dig], abs(ri[dig] - i) * max(j - 1, n - j));
                ans[dig] = max(ans[dig], abs(lj[dig] - j) * max(i - 1, n - i));
                ans[dig] = max(ans[dig], abs(rj[dig] - j) * max(i - 1, n - i));
            }
        }

        for(int i = 0; i <= 9; i++) {
            printf("%d ", ans[i]);
        }
        printf("\n");
    }

#ifdef CitricAcid
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
/*
# author : CitricAcid
# date : 2020/12/10
*/
		    	    	 	   	  			  		   	