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

#define rep(i, n, args...) for (int i = 0, ##args; i < n; i++)
#define repr(i, s, n, args...) for (int i = s, ##args; i < n; i++)

typedef long long ll;

constexpr int N = 2005;

int a[N][N], most[10][2], least[10][2], ans[10];

void pre(int n) {
    fill(most[0], most[10], 0);
    fill(least[0], least[10], n);
    rep(i, n) {
        rep(j, n) {
            auto itmx = most[a[i][j]];
            itmx[0] = max(itmx[0], i);
            itmx[1] = max(itmx[1], j);
            auto itls = least[a[i][j]];
            itls[0] = min(itls[0], i);
            itls[1] = min(itls[1], j);
        }
    }
}

void solve(int n) {
    fill(ans, ans+10, 0);
    rep(i, n) {
        rep(j, n) {
            int d = a[i][j];
            int xlen = max(n - i - 1, i), ylen = max(n - j - 1, j);
            int hxlen = max(most[d][0] - i, i - least[d][0]);
            int hylen = max(most[d][1] - j, j - least[d][1]);
            ans[d] = max(ans[d], xlen * hylen);
            ans[d] = max(ans[d], ylen * hxlen);
        }
    }
}

int main() {
    int t;
    scanf("%d", &t);
    while(t--) {
        int n;
        scanf("%d", &n);
        rep(i, n) {
            rep(j, n) {
                scanf("%1d", &a[i][j]);
            }
        }
        pre(n);
        solve(n);
        rep(i, 10) {
            cout << ans[i] << ' ';
        }
        cout << endl;
    }
}