#include<bits/stdc++.h>
#define ll long long
#define rep(i, m, n) for (int i = m; i <= n; i++)
#define per(i, m, n) for (int i = m; i >= n; i--)
#define FOR(i, m, n, k) for (int i = m; i <= n; i += k)
#define ROF(i, m, n, k) for (int i = m; i >= n; i -= k)
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define INF 0x3f3f3f3f
using namespace std;

const int maxn = 305;

char grid[maxn][maxn];

int check(int N, int tot, int mod[3]) {
    int cnt = 0;
    rep(i, 1, N) {
        rep(j, 1, N) {
            if (j % 3 == mod[i % 3] && grid[i][j] == 'X') cnt++;
        }
    }
    if (cnt <= tot / 3) {
        rep(i, 1, N) {
            rep(j, 1, N) {
                if (j % 3 == mod[i % 3] && grid[i][j] == 'X') cout << 'O';
                else cout << grid[i][j];
            }
            cout << "\n";
        }
        return 1;
    }
    return 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        int N, tot = 0;
        cin >> N;
        rep(i, 1, N) cin >> (grid[i] + 1);
        rep(i, 1, N) {
            rep(j, 1, N) {
                if (grid[i][j] == 'X') tot++;
            }
        }
        int mod[3] = {0, 1, 2};
        if (check(N, tot, mod)) continue;
        mod[0] = 1, mod[1] = 2, mod[2] = 0;
        if (check(N, tot, mod)) continue;
        mod[0] = 2, mod[1] = 0, mod[2] = 1;
        check(N, tot, mod);
    }
    return 0;
}
