#include <bits/stdc++.h>

#define int long long
#define endl "\n"
using namespace std;

signed main(){
    #ifdef MY
    freopen("in.txt", "r", stdin);
    #endif // MY

    int t;
    cin >> t;
    while (t--){

        int n;
        cin >> n;

        vector<vector<int>> rights(n, vector<int>(10, -1));
        vector<vector<int>> lefts(n, vector<int>(10, n + 1));
        vector<vector<int>> ups(n, vector<int>(10, n + 1));
        vector<vector<int>> downs(n, vector<int>(10, -1));

        vector<int> right_col(10, -1), left_col(10, n + 1), up_row(10, n + 1), down_row(10, -1);
        vector<int> ans(10);
        vector<vector<int>> arr(n, vector<int>(n));

        for (int i = 0; i < n; ++i){
            string s;
            cin >> s;
            for (int j = 0; j < n; ++j)
                arr[i][j] = s[j] - '0';
        }

        for (int j = n - 1; j >= 0; --j){
            for (int i = 0; i < n; ++i){
                if (right_col[arr[i][j]] == -1)
                    right_col[arr[i][j]] = j;
                if (rights[i][arr[i][j]] == -1)
                    rights[i][arr[i][j]] = j;
            }
        }
        for (int j = 0; j < n; ++j){
            for (int i = 0; i < n; ++i){
                if (left_col[arr[i][j]] == n + 1)
                    left_col[arr[i][j]] = j;
                if (lefts[i][arr[i][j]] == n + 1)
                    lefts[i][arr[i][j]] = j;
            }
        }
        for (int i = n - 1; i >= 0; --i){
            for (int j = 0; j < n; ++j){
                if (down_row[arr[i][j]] == -1)
                    down_row[arr[i][j]] = i;
                if (downs[j][arr[i][j]] == -1)
                    downs[j][arr[i][j]] = i;

            }
        }
        for (int i = 0; i < n; ++i){
            for (int j = 0; j < n; ++j){
                if (up_row[arr[i][j]] == n + 1)
                    up_row[arr[i][j]] = i;
                if (ups[j][arr[i][j]] == n + 1)
                    ups[j][arr[i][j]] = i;
            }
        }

        for (int i = 0; i < n; ++i){
            for (int j = 0; j < n; ++j){
                for (int c = 0; c < 10; ++c){
                    bool b1 = false, b2 = false, b3 = false, b4 = false;
                    bool f1 = false, f2 = false, f3 = false, f4 = false;
                    if (downs[j][c] == -1){
                        downs[j][c] = i;
                        f1 = true;
                    }
                    if (ups[j][c] == n + 1){
                        ups[j][c] = i;
                        f2 = true;
                    }
                    if (lefts[i][c] == n + 1){
                        lefts[i][c] = j;
                        f3 = true;
                    }
                    if (rights[i][c] == -1){
                        rights[i][c] = j;
                        f4 = true;
                    }

                    if (right_col[c] == -1){
                        right_col[c] = j;
                        b1 = true;
                    }
                    if (left_col[c] == n + 1){
                        left_col[c] = j;
                        b2 = true;
                    }
                    if (down_row[c] == -1){
                        down_row[c] = i;
                        b3 = true;
                    }
                    if (up_row[c] == n + 1){
                        up_row[c] = i;
                        b4 = true;
                    }
                    ans[c] = max(ans[c], abs(i - downs[j][c]) * max(abs(j - right_col[c]), abs(j - left_col[c])));
                    ans[c] = max(ans[c], abs(i - ups[j][c]) * max(abs(j - right_col[c]), abs(j - left_col[c])));

                    ans[c] = max(ans[c], abs(j - lefts[i][c]) * max(abs(i - up_row[c]), abs(i - down_row[c])));
                    ans[c] = max(ans[c], abs(j - rights[i][c]) * max(abs(i - up_row[c]), abs(i - down_row[c])));
                    if (b1)
                        right_col[c] = -1;
                    if (b2)
                        left_col[c] = n + 1;
                    if (b3)
                        down_row[c] = -1;
                    if (b4)
                        up_row[c] = n + 1;

                    if (f1)
                        downs[j][c] = -1;
                    if (f2)
                        ups[j][c] = n + 1;
                    if (f3)
                        lefts[i][c] = n + 1;
                    if (f4)
                        rights[i][c] = -1;
                }
            }
        }

        for (int i : ans)
            cout << i << " ";
        cout << endl;
    }

}
