#include <bits/stdc++.h>

using namespace std;
#define lli long long int
const int N = 400;
int t, n, m;
char a[N][N];
int kol[5][5];
void solve () {
	cin >> n;
	int minix=1e7, minio=1e7, indx=1e7, indo=1e7;
	memset(kol, 0, sizeof(kol));
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> a[i][j];
			if (a[i][j]=='X') {
				kol[0][(i-j+3000)%3]++;
			}
			if (a[i][j]=='O') {
				kol[1][(i-j+3000)%3]++;
			}
		}
	}
	for (int i = 0; i < 3; i++) {
		if (minix > kol[0][i]) {
			minix = kol[0][i];
			indx=i;
		}
		if (minio > kol[1][i]) {
			minio = kol[1][i];
			indo=i;
		}
	//	cout << kol[0][i] << " " << kol[1][i] << endl;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (a[i][j]=='X' && ((i-j+3000)%3)==indx) {
				a[i][j]='O';
			}
		}
	}
	cout << endl;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cout << a[i][j];
		}
		cout << endl;
	}
return;
}

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

return 0;
}

