#include <bits/stdc++.h>
using namespace std;
// #define int  long long int
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define gcd __gcd
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(i) i.begin(),i.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define set_bit __builtin_popcount //gives number of set_bits
#define ff first
#define ss second
#define cases(t) int t;cin>>t; rep(casn,1,t+1)
#define el cout<<"\n";
#define deci(n) int n; scanf("%lld",&n);
#define decs(n) string n; cin>>n;
#define sz(v) v.size()
#define repit(m) for(auto it=m.begin();it!=m.end();it++)
#define debx cout<<"->";
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cYES cout<<"YES\n";
#define cNO cout<<"NO\n";
#define ins insert
#define imax 800000000000000000
#define imin -1000000000000000000
//  cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
//  IIITA
//SUNEET KUMAR -->  ਸੁਨੀਤ
// scanning numbers extremely fast/////////

void fs(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}
// ========================================
int power(int a,int x)
{
    a%=mod;
    int res=1;
    while(x>0)
    {
        if(x&1)
        res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}

int max(int a,int b)
{
    if(a>b)
    {
        return a;
    }
    else
    {
        return b;
    }
}

int min(int a,int b)
{
    if(a>b)
    {
        return b;
    }
    else
    {
        return a;
    }
}
int madd(int a,int b)
{
    int ans;
    ans=(a%mod+b%mod)%mod;
    return ans;
}
int mmult(int a,int b)
{
    int ans=1;
    ans=((a%mod)*(b%mod))%mod;
    return ans%mod;
}
int modinverse(int a)
{
    return power(a,mod-2);
}
// int fact[500004];
// void Factorial()
// {
//     fact[0]=1;
//     for(int i=1;i<=500001;i++)
//     {
//         fact[i]=mmult(fact[i-1],i);
//     }
// }
// int ncr(int n,int r)
// {
//     if(r>n)
//     {
//         return 0;
//     }
//     if(n==r||r==0)
//     {
//         return 1;
//     }
//     if(n==0)
//     {
//         return 0;
//     }
//     mmult(fact[n],modinverse(mmult(fact[r],fact[n-r])));
// }
void solve()
{
    int n;cin>>n;
    int a[n+10][n+10];
    string s;
    for(int i=1;i<=n;i++)
    {   
        string s;cin>>s;
        for(int j=0;j<s.length();j++)
        {
            a[i][j+1]=s[j]-'0';
        }
    }
    // map<int,int>m;
    int m[12],mxr[12],mxc[12],mir[12],mic[12];
    memset(m,0,sizeof(m));
    memset(mxr,0,sizeof(mxr));memset(mxc,0,sizeof(mxc));
    // memset(mic,0,sizeof(mic));
    // memset(mir,0,sizeof(mir));
    for(int i=0;i<=10;i++)
    {
        mic[i]=100000;
        mir[i]=1000000;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            int x=a[i][j];
            mir[x]=min(mir[x],i);
            mic[x]=min(mic[x],j);
            mxr[x]=max(mxr[x],i);
            mxc[x]=max(mxc[x],j);
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            int x=a[i][j];
            m[x]=max(m[x],max(mxr[x]-i,i-mir[x])*(max(n-j,j-1)));
            m[x]=max(m[x],max(mxc[x]-j,j-mic[x])*(max(n-i,i-1)));
        }
    }
    // debx;
    for(int i=0;i<10;i++)
    {
        cout<<m[i]<<" ";
    }
    el
}
signed main()
{
    // fastio;
    cases(t)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
        // cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
    }
}
