#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

void solve() {
	int n;
	cin >> n;
	vector<string> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	if (n < 3) {
		for (int i = 0; i < n; i++) {
			cout << a[i] << '\n';
		}
		return;
	}

	int cnt = 0;
	vector<int> t(3);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (a[i][j] == 'X') {
				cnt++;
				t[(i + j) % 3]++;
			}
		}
	}

	for (int i = 0; i < 3; i++) {
		if (t[i] <= cnt / 3) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					if (a[j][k] == 'X' && (j + k) % 3 == i)
						a[j][k] = 'O';
				}
			}

			for (int j = 0; j < n; j++) {
				cout << a[j] << '\n';
			}
			return;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	cin >> q;
	for (; q > 0; q--) {
		solve();
		//cout << '\n';
	}
}