#include <bits/stdc++.h>

using namespace std;

int main(int argc, char **argv) {
	int t, n, a;
	cin >> t;
	
	while (t--) {
		cin >> n;
		vector<string> a(n);
		for (auto &_: a) cin >> _;
		
		vector<int> c(3);
		for (int y = 0; y < n; y++)
			for (int x = 0; x < n; x++)
				if (a[y][x] == 'X')
					c[(y + x) % 3]++;
				
		int tc = min_element(c.begin(), c.end()) - c.begin();
		
		for (int y = 0; y < n; y++)
			for (int x = 0; x < n; x++)
				if (a[y][x] == 'X' && ((y + x) % 3) == tc)
					a[y][x] = 'O';

		for (auto &_: a) cout << _ << endl;
		
		vector<int> vc(n);
		int ok = 0;
		for (int i = 0; i < n; i++) {
			int hc = 0;
			for (int j = 0; j < n; j++) {
				if (a[i][j] == 'O') ok++;
				if (a[i][j] == 'X') {
					vc[j]++;
					hc++;
					assert(vc[j] < 3);
					assert(hc < 3);
				} else {
					vc[j] = 0;
					hc = 0;
				}
			}
		}
		assert (ok <= accumulate(c.begin(), c.end(), 0) / 3);
		
		//cout << endl;
	}
	
	return 0;
}
