#include <bits/stdc++.h>
using namespace std;
int n, i, j, t, v;
string a[333];

int main() {
	cin >> t;
	while (t--) {
		cin >> n;
		int c[3] = {0, 0, 0};
		for (i = 0; i < n; i++) {
			cin >> a[i];
			for (j = 0; j < n; j++)
				if (a[i][j] == 'X')
					c[(i + j) % 3]++;
		}
		v = min_element(c, c + 3) - c;
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++)
				if (a[i][j] == 'X' && (i + j) % 3 == v)
					a[i][j] = 'O';
			cout << a[i] << endl;
		}
	}
}