#include<bits/stdc++.h>
using namespace std;
#define ll long long int

ll a[2005][2005];

ll first[10];
ll last[10];
ll first_col[2005][10];
ll last_col[2005][10];

ll first1[10];
ll last1[10];
ll first_col1[2005][10];
ll last_col1[2005][10];

ll ans[10];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll t;
    cin>>t;
    
    while(t--){
        ll n;
        cin>>n;
        
        for(ll j=0;j<=9;j++){
            first[j]=-1;
            last[j]=-1;
        }
        for(ll i=0;i<n;i++){
            for(ll j=0;j<=9;j++){
                first_col[i][j]=-1;
                last_col[i][j]=-1;
            }
            for(ll j=0;j<n;j++){
                char ch;
                cin>>ch;
                a[i][j]=ch-'0';
                
                last_col[i][a[i][j]]=j;
                if(first_col[i][a[i][j]]==-1){
                    first_col[i][a[i][j]]=j;
                }
            }
            for(ll j=0;j<=9;j++){
                if(first_col[i][j]!=-1){
                    last[j]=i;
                    if(first[j]==-1){
                        first[j]=i;
                    }
                }
            }
        }  
        for(ll i=0;i<=9;i++){
            ans[i]=0;
        }
        for(ll i=0;i<n;i++){
            for(ll j=0;j<=9;j++){
                if(first_col[i][j]!=-1){
                    ll b=0;
                    ll h=0;
                    b=last_col[i][j]-first_col[i][j];
                    h=i-first[j];
                    ans[j]=max(ans[j],b*h);
                    //cout<<b*h<<"\n";
                    h=last[j]-i;
                    ans[j]=max(ans[j],b*h);
                    //cout<<b*h<<"\n";
                    
                    ans[j]=max(ans[j],b*i);
                    //cout<<b*i<<"\n";
                    ans[j]=max(ans[j],b*(n-1-i));
                    //cout<<b*(n-1-i)<<"\n";
                    
                    b=last_col[i][j];
                    h=i-first[j];
                    ans[j]=max(ans[j],b*h);
                    //cout<<b*h<<"\n";
                    h=last[j]-i;
                    ans[j]=max(ans[j],b*h);
                    //cout<<b*h<<"\n";

                    b=n-1-first_col[i][j];
                    h=i-first[j];
                    ans[j]=max(ans[j],b*h);
                    //cout<<b*h<<"\n";
                    h=last[j]-i;
                    ans[j]=max(ans[j],b*h);
                    //cout<<b*h<<"\n";
                }
            }
        }

        // for(ll i=0;i<=9;i++){
        //     cout<<ans[i]<<" ";
        // }
        // cout<<"\n";

        for(ll j=0;j<=9;j++){
            first1[j]=-1;
            last1[j]=-1;
        }
        for(ll j=0;j<n;j++){
            for(ll i=0;i<=9;i++){
                first_col1[j][i]=-1;
                last_col1[j][i]=-1;
            }
            for(ll i=0;i<n;i++){
                last_col1[j][a[i][j]]=i;
                if(first_col1[j][a[i][j]]==-1){
                    first_col1[j][a[i][j]]=i;
                }
            }
            for(ll i=0;i<=9;i++){
                if(first_col1[j][i]!=-1){
                    last1[i]=j;
                    if(first1[i]==-1){
                        first1[i]=j;
                    }
                }
            }
        }  
        
        for(ll j=0;j<n;j++){
            for(ll i=0;i<=9;i++){
                if(first_col1[j][i]!=-1){
                    ll b=0;
                    ll h=0;
                    b=last_col1[j][i]-first_col1[j][i];
                    h=j-first1[i];
                    ans[i]=max(ans[i],b*h);
                    //cout<<ans[i]<<"\n";
                    h=last1[i]-j;
                    ans[i]=max(ans[i],b*h);
                    //cout<<ans[i]<<"\n";
                    
                    ans[i]=max(ans[i],b*j);
                    //cout<<ans[i]<<"\n";
                    ans[i]=max(ans[i],b*(n-1-j));
                    //cout<<ans[i]<<"\n";

                    b=last_col1[j][i];
                    h=j-first1[i];
                    ans[i]=max(ans[i],b*h);
                    //cout<<ans[i]<<"\n";
                    h=last1[i]-j;
                    ans[i]=max(ans[i],b*h);
                    //cout<<ans[i]<<"\n";
                    
                    b=n-1-first_col1[j][i];
                    h=j-first1[i];
                    ans[i]=max(ans[i],b*h);
                    //cout<<ans[i]<<"\n";
                    h=last1[i]-j;
                    ans[i]=max(ans[i],b*h);
                    //cout<<ans[i]<<"\n";
                }
            }
            // for(ll i=0;i<=9;i++){
            //     cout<<ans[i]<<" ";
            // }
            // cout<<"\n";
        }

        for(ll i=0;i<=9;i++){
            cout<<ans[i]<<" ";
        }
        cout<<"\n";
            
    }
        
        
}

/*
4 4 1 0 0 0 0 0 0 0
0 0 0 0 0 1 0 1 0 0
9 6 9 9 6 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
18 49 49 49 49 15 0 30 42 42
*/


