/**
 *	author:  Estrerusti
 *	created: 05.12.2020 10:07:42
**/
#include <bits/stdc++.h>

using namespace std;
#define INF 1e9

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int tt;
	cin >> tt;
	while (tt--) {
		int n;
		cin >> n;
		vector<vector<char>> ipt(n + 1, vector<char>(n + 1));
		vector<int> mnr(10, INF), mxr(10), mnc(10, INF), mxc(10);
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				cin >> ipt[i][j];
				int now = ipt[i][j] - '0';
				mnr[now] = min(mnr[now], i);
				mxr[now] = max(mxr[now], i);
				mnc[now] = min(mnc[now], j);
				mxc[now] = max(mxc[now], j);
			}
		}
		vector<int> ans(10);
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				int now = ipt[i][j] - '0';
				ans[now] = max(ans[now], max(n - j, j - 1) * max(mxr[now] - i, i - mnr[now]));
				ans[now] = max(ans[now], max(n - i, i - 1) * max(mxc[now] - j, j - mnc[now]));
			}
		}
		for (int i = 0; i < 10; i++) {
			cout << ans[i] << " ";
		}
		cout << '\n';
	}
	return 0;
}
