// < Rahil Malhotra / ViciousCoder >
#include "bits/stdc++.h"
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main() 
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string arr[n];
        int maxrow[11]={};
        int maxcol[11]={};
        int minrow[11]={};
        int mincol[11]={};
        for(int i=0;i<11;i++)
        {
            minrow[i]=n+5;
            mincol[i]=n+5;
        }
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            for(int j=0;j<n;j++)
            {
                maxrow[arr[i][j]-'0']=max(maxrow[arr[i][j]-'0'],i);
                maxcol[arr[i][j]-'0']=max(maxcol[arr[i][j]-'0'],j);
                minrow[arr[i][j]-'0']=min(minrow[arr[i][j]-'0'],i);
                mincol[arr[i][j]-'0']=min(mincol[arr[i][j]-'0'],j);
            }
        }
        int finans[11]={};
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                int get=arr[i][j]-'0';
                if(arr[0][j]-'0'==get)
                    finans[get]=max(finans[get],i*max(n-1-j,j));
                else
                {
                    finans[get]=max(finans[get],i*(maxcol[get]-j));
                    finans[get]=max(finans[get],i*(j-mincol[get]));
                }
                if(arr[n-1][j]-'0'==get)
                    finans[get]=max(finans[get],(n-1-i)*max(n-1-j,j));
                else
                {
                    finans[get]=max(finans[get],(n-1-i)*(maxcol[get]-j));
                    finans[get]=max(finans[get],(n-1-i)*(j-mincol[get]));
                }

                if(arr[i][0]-'0'==get)
                    finans[get]=max(finans[get],j*max(n-1-i,i));
                else
                {
                    finans[get]=max(finans[get],j*(maxrow[get]-i));
                    finans[get]=max(finans[get],j*(i-minrow[get]));
                }
                if(arr[i][n-1]-'0'==get)
                    finans[get]=max(finans[get],(n-1-j)*max(n-1-i,i));
                else
                {
                    finans[get]=max(finans[get],(n-1-j)*(maxrow[get]-i));
                    finans[get]=max(finans[get],(n-1-j)*(i-minrow[get]));
                }
            }
        }
        for(int i=0;i<10;i++)
            cout<<finans[i]<<" ";
        cout<<endl;
    }
} 