#pragma optimization_level 3
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);             \
    cout << fixed;           \
    cout << setprecision(10);
#define randomINIT mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rep for (ll i = 0; i < n; i++)
#define fori(a, b, c) for (ll i = a; i <= b; i = i + c)
#define pr(val) cout << val << endl

int main()
{
    ll t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        string a[n];
        ll info[10][2], minfo[10][2]; //[digit][r] , [digit][c]
        for (int i = 0; i < 10; i++)
            for (int j = 0; j < 2; j++)
            {
                info[i][j] = -1;
                minfo[i][j] = 3000;
            }

        rep cin >> a[i];

        for (ll i = 0; i < n; i++)
        {
            for (ll j = 0; j < n; j++)
            {
                ll d = a[i][j] - '0';
                info[d][0] = max(info[d][0], i);
                info[d][1] = max(info[d][1], j);
                minfo[d][0] = min(minfo[d][0], i);
                minfo[d][1] = min(minfo[d][1], j);
            }
        }

        ll cur_area = 0;
        for (ll d = 0; d < 10; d++)
        {
            cur_area = 0;
            for (ll i = 0; i < n; i++)
            {
                for (ll j = 0; j < n; j++)
                {
                    if (a[i][j] == char(d + '0'))
                    {
                        ll tmp1 = max(j, n - j - 1) * max(i - minfo[d][0], info[d][0] - i);
                        ll tmp2 = max(i, n - i - 1) * max(j - minfo[d][1], info[d][1] - j);
                        cur_area = max({cur_area, tmp1, tmp2});
                    }
                }
            }
            cout << cur_area << " ";
        }

        cout << '\n';
    }
}