#include<bits/stdc++.h>
using namespace std;
int cnt[3], n;
char s[305][305];
int main() {
    int T;
    cin >> T;
    while (T--) {
        scanf("%d", &n);
        int all = 0;
        for (int i = 0; i < 3; ++i) cnt[i] = 0;
        for (int i = 0; i < n; ++i) {
            scanf("%s", s[i]);
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (s[i][j] != '.') {
                    ++cnt[(i + j) % 3];
                    ++all;
                }
            }
        }
        for (int i = 0; i < 3; ++i) {
            if (cnt[i] * 3 <= all) {
                for (int j = 0; j < n; ++j) {
                    for (int k = 0; k < n; ++k) {
                        if ((j + k) % 3 == i && s[j][k] == 'X') s[j][k] = 'O';
                    }
                }
                break;
            }
        }
        for (int i = 0; i < n; ++i) puts(s[i]);
    }
}
