#include <bits/stdc++.h>
using namespace std;

// #define ll long long
#define INF 1e9+7

typedef vector <int> vi;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int ct;
    cin >> ct;
    while (ct--) {
        int n;
        cin >> n;
        int m = n;

        int mat[n][m];
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            for (int j = 0; j < m; j++) {
                char c = s[j];
                mat[i][j] = c-'0';
            }
        }

        vi res(10, 0);
        for (int d = 0; d < 10; d++) {
            vi lf(n, INF), ll(n, 0), cf(n, INF), cl(n, 0);
            int L = INF, R = 0, C = INF, B = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (mat[i][j] == d) {
                        lf[i] = min(lf[i], j);
                        ll[i] = max(ll[i], j);
                        cf[j] = min(cf[j], i);
                        cl[j] = max(cl[j], i);

                        L = min(L, j);
                        R = max(R, j);
                        C = min(C, i);
                        B = max(B, i);
                    }
                }
            }
            
            if(L == INF){
                res[d] = 0;
                continue;
            }
            
            for (int i = 0; i < n; i++) {
                if (lf[i] == INF) continue;
                if (lf[i] != ll[i]) {
                    int base = (ll[i]-lf[i]);
                    int alt = max(i, n-i-1);
                    res[d] = max(res[d], base*alt);
                }
                int base = max(max(lf[i], m-lf[i]-1), max(ll[i], m-ll[i]-1));
                int alt = max(i-C, B-i);
                res[d] = max(res[d], base*alt);
            }
            // (2, 1) (2, 8)* (8, 3)

            for (int j = 0; j < m; j++) {
                if (cf[j] == INF) continue;
                if (cf[j] != cl[j]) {
                    int base = (cl[j]-cf[j]);
                    int alt = max(j, m-j-1);
                    res[d] = max(res[d], base*alt);
                }
                int base = max(max(cf[j], n-cf[j]-1), max(cl[j], n-cl[j]-1));
                int alt = max(j-L, R-j);
                res[d] = max(res[d], base*alt);
            }
            
            // for (int i : lf) cout << i << " "; cout << endl;
            // for (int i : ll) cout << i << " "; cout << endl;
            // for (int i : cf) cout << i << " "; cout << endl;
            // for (int i : cl) cout << i << " "; cout << endl;
        }

        for (int i : res) cout << i << " "; cout << endl;
    }   
}
