#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define pb push_back
#define empb emplace_back
#define mp make_pair
#define mtp make_tuple
#define umap unordered_map
#define uset unordered_set
#define sqr(a) ((a) * (a))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(v) reverse(v.begin(), v.end());
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand((ui)time(NULL))

#define endl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

const ld eps = 1e-9;
const ld PI = acos(-1);
const ll infll = 1e18 + 1329;
const int inf = 1e9 + 1329;
const ld E = 2.71828182845904523536028747135266249775724709369995;
vector<ll> mods = {1000065757, 1000570057, 1004571329, 1000580179, 1000057769, 1000001329, 1000006957, 1000056157, 1001001329};
vector<ll> hashpows = {29, 31, 37, 43, 47, 53, 59, 157, 179, 257};
mt19937 rnd((ui) chrono::high_resolution_clock::now().time_since_epoch().count() + (ui) 1329);
ll hashmod = mods[rnd() % mods.size()];
ll hashpow = hashpows[rnd() % hashpows.size()];
//#define int ll

template <class T>
istream& operator>> (istream& stream, vector<T>& v) { for(int i = 0; i < v.size(); ++i) { stream >> v[i]; } return stream; }
template <class T>
ostream& operator<< (ostream& stream, vector<T>& v) { for(int i = 0; i < v.size(); ++i) { stream << v[i] << " "; } stream << '\n'; return stream; }

int n;

int solve (vector<vector<char>>& a, char d) {
    int fi = -1;
    for (int i = 0; i < n && fi == -1; ++i)
        for (int j = 0; j < n && fi == -1; ++j)
            if (a[i][j] == d)
                fi = i;
    int si = -1;
    for (int i = n - 1; i >= 0 && si == -1; --i)
        for (int j = 0; j < n && si == -1; ++j)
            if (a[i][j] == d)
                si = i;
    if (fi == si) return 0;
    int ma = 0;
    for (int i = fi; i <= si; ++i) {
        for (int j = 0; j < n; ++j) {
            if (a[i][j] != d) continue;
            ma = max(ma, (i - fi) * max(j, n - 1 - j));
            ma = max(ma, (si - i) * max(j, n - 1 - j));
        }
    }
    return ma;
}

signed main() {
    fastio();
    int t; cin >> t;
    while (t--) {
        cin >> n;
        vector<vector<char>> a (n, vector<char> (n)); cin >> a;
        vector<vector<char>> b = a;
        vector<int> ma (10, 0);
        for (int d = '0'; d <= '9'; ++d) {
            ma[d - '0'] = max(ma[d - '0'], solve(b, d));
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                b[j][(n - 1) - i] = a[i][j];
            }
        }
        for (int d = '0'; d <= '9'; ++d) {
            ma[d - '0'] = max(ma[d - '0'], solve(b, d));
        }
        cout << ma;
    }
}
