#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
int mod = 1000000007;
struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};


bool compj(pair<int,int> i1,pair<int,int> i2)
{
    return (i1.second<i2.second);
}
bool compi(pair<int, int> i1, pair<int, int> i2)
{
    return (i1.first<i2.first); 
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int i,j;
        string a[n];
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        char k;
        for(k='0';k<='9';k++)
        {
            vector<pair<int,int>> res;
            for(i=0;i<n;i++)
            {
                for(j=0;j<n;j++)
                {
                    if(a[i][j]==k)
                    res.push_back({i,j});
                }
            }
            int a1=-1,a2=-1;
            if((int)res.size()<2)
            a1=0;
            else
            {
                sort(res.begin(),res.end(),compj);
                int d=res.size();
                for(i=0;i<d;i++)
                {
                    a1=max(a1,max(res[i].first,n-1-res[i].first)*max(res[i].second-res[0].second,res[d-1].second-res[i].second));
                }
            }
            if((int)res.size()<2)
            a2=0;
            else 
            {
                sort(res.begin(), res.end(), compi);
                int d = res.size();
                for (i = 0; i < d; i++)
                {
                    a1 = max(a1, max(res[i].second, n - 1 - res[i].second) * max(res[i].first - res[0].first, res[d - 1].first - res[i].first));
                }
            }
            cout<<max(a1,a2)<<" ";
        }
        cout<<"\n";
    }
}
