#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;

typedef long long ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define sz(x) (int)x.size()
#define dbg(x) cerr << #x << " = " << x << '\n'

const int MOD = 1e9+7; //998244353;
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;

int add(int a, int b, int mod = MOD) {
    a += b;
    while(a >= mod) a -= mod;
    while(a < 0) a += mod;
    return a;
}

int mul(int a, int b, int mod = MOD) {
    return (a * 1LL * b) % mod;
}

void setIO(const string& s) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

const int N = 310;

int n;
char mat[N][N];

void solve() {
    cin >> n;
    for(int i=1; i<=n; ++i) {
        string s; cin >> s;
        for(int j=1; j<=n; ++j) {
            mat[i][j] = s[j-1];
        }
    }
    vector<vector<pair<int,int>>> pos(3);
    for(int i=1; i<=n; ++i) {
        for(int j=1; j<=n; ++j) {
            if(mat[i][j]=='X') pos[(i+j)%3].eb(i,j);
        }
    }
    vector<pair<int,int>> best;
    int mnsz = min({sz(pos[0]),sz(pos[1]),sz(pos[2])});
    if(mnsz==sz(pos[0])) best = pos[0];
    if(mnsz==sz(pos[1])) best = pos[1];
    if(mnsz==sz(pos[2])) best = pos[2];
    for(auto& [i,j] : best) {
        mat[i][j] = 'O';
    }
    for(int i=1; i<=n; ++i) {
        for(int j=1; j<=n; ++j) {
            cout << mat[i][j];
        }
        cout << '\n';
    }
}

signed main() {
    setIO("input");
    
    int t; cin >> t;
    while(t--)
        solve();
    
}