#include <bits/stdc++.h>  

// #include<iostream>
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) 
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) 
#define forrc(i,l,r) for (int i= (int)(r); i>= (int)(l); --i)

#define pb push_back
#define fi first
#define se second
#define mp make_pair

#define all(x) (x).begin(), (x).end() 
#define rall(x) (x).rbegin, (x).rend() 


#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)


#define present(c,x) ((c).find(x) != (c).end())


#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())

 using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
typedef long long ll;
typedef unsigned long long int ull;
int pow(int n, int i){
    int a=n,ans=1;
    while(i>0){
        if(i&1){
            ans*=a;
        }
        a*=a;
        i=i>>1;
    }
    return ans;
}
int main(){
    int MOD=1e9+7;
    int t,n;
    cin >> t;
    while(t--){
        cin >> n;
        vector<string> v(n);
        for0(i,n){
            cin >> v[i];
        }
        vi max_row(10);
        vi min_row(10);
        vi max_col(10);
        vi min_col(10);
        for0(i,10){
            max_row[i]=n;
            max_col[i]=n;
            min_col[i]=-1;
            min_row[i]=-1;
        }
        for0(d,10){
            for0(j,n){
                for0(k,n){
                    if(v[j][k]-'0'==d){
                        min_row[d]=j;
                        break;
                    }
                }
                if(min_row[d]>-1)break;
            }
        }
        for0(d,10){
            for0(j,n){
                for0(k,n){
                    if(v[k][j]-'0'==d){
                        min_col[d]=j;
                        break;
                    }
                }
                if(min_col[d]>-1)break;
            }
        }
        for0(d,10){
            forr0(j,n){
                for0(k,n){
                    if(v[j][k]-'0'==d){
                        max_row[d]=j;
                        break;
                    }
                }
                if(max_row[d]<n)break;
            }
        }
        for0(d,10){
            forr0(j,n){
                for0(k,n){
                    if(v[k][j]-'0'==d){
                        max_col[d]=j;
                        break;
                    }
                }
                if(max_col[d]<n)break;
            }
        }
        // for0(d,10){
        //     cout << min_row[d] << " " << max_row[d] << " " << min_col[d] << " " << max_col[d] << endl;
        // }
        vi ans(10);
        int k;
        for0(d,10){
            ans[d]=0;
            for0(i,n){
                for0(j,n){
                    if(v[i][j]-'0'==d){
                       k=max(max(n-1-j,j)*max(max_row[d]-i,i-min_row[d]),max(n-i-1,i)*max(max_col[d]-j,j-min_col[d]));
                       ans[d]=max(ans[d],k); 
                    }
                }
            }
        }
        for0(d,10){
            cout << ans[d] << " ";
        }
        cout << endl;
    }
  
}
        