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

signed main()
{
  int t;
  cin>>t;
  for(int ii=0;ii<t;ii++)
  {
     int n;
     cin>>n;
     int arr[n+2][n+2];
     for(int i=1;i<=n;i++)
     {
         string s;
         cin>>s;
         for(int j=1;j<=n;j++)
            arr[i][j]=s[j-1]-'0';
     }
     vector<int> row[n+2][11];
     vector<int> roww[11];
     for(int i=1;i<=n;i++)
     {
         for(int j=1;j<=n;j++)
         {
             int a=arr[i][j];
             row[i][a].push_back(j);
             roww[a].push_back(i);
         }
     }
     vector<int> col[n+2][11];
     vector<int> coll[11];
     for(int i=1;i<=n;i++)
     {
         for(int j=1;j<=n;j++)
         {
             int a=arr[j][i];
             col[i][a].push_back(j);
             coll[a].push_back(i);
         }
     }
      for(int i=0;i<=9;i++)
      {
          sort(roww[i].begin(),roww[i].end());
          sort(coll[i].begin(),coll[i].end());
          for(int j=1;j<=n;j++)
          {
          sort(row[j][i].begin(),row[j][i].end());
          sort(col[j][i].begin(),col[j][i].end());
          }
      }

     for(int i=0;i<=9;i++)
     {
         //first taking base along row
         int g=0;
         for(int j=1;j<=n;j++)
         {
             for(int h=0;h<row[j][i].size();h++)
             {
                 int ss=row[j][i].size()-1;
                 int a=row[j][i][h];
                 int b=row[j][i][ss];
                 int cc=roww[i].size()-1;
                 int c=roww[i][cc];
                 int d=roww[i][0];
                 int e=abs(c-j);
                 int f=abs(d-j);
                 f=max(e,f);
 // cout<<"for row "<<i<<" "<<j<<" "<<h<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
                 int l=abs(a-b)*f;
                 l=max(l,abs(a-n)*f);
                 l=max(l,abs(b-1)*f);
               //  cout<<"l between row "<<l<<" "<<f<<endl;
                 int kk=abs(n-j);
                 kk=max(kk,j-1);
                 l=max(l,kk*abs(a-b));
              //   cout<<"l is in row "<<l<<endl;
                 g=max(l,g);
             }
         }
         //now taking base along column
         for(int j=1;j<=n;j++)
         {
             for(int h=0;h<col[j][i].size();h++)
             {
                 int ss=col[j][i].size()-1;
                 int a=col[j][i][h];
                 int b=col[j][i][ss];
                 int cc=coll[i].size()-1;
                 int c=coll[i][cc];
                 int d=coll[i][0];
                 int e=abs(c-j);
                 int f=abs(d-j);
                 f=max(e,f);
 // cout<<"for col "<<i<<" "<<j<<" "<<h<<" "<<a<<" "<<b<<" "<<c<<" "<<d<<endl;

                 int l=abs(a-b)*f;
                 l=max(l,abs(a-n)*f);
                 l=max(l,abs(b-1)*f);
           //      cout<<"l between col "<<l<<" "<<f<<endl;
                 int kk=abs(n-j);
                 kk=max(kk,j-1);
                 l=max(l,kk*abs(a-b));
              //   cout<<"l is in col "<<l<<endl;
                 g=max(l,g);
             }
         }
         cout<<g<<" ";
     }
     cout<<endl;
  }
return 0;
}
