#include<bits/stdc++.h>
#define fi first
#define sc second
#define pb emplace_back
#define all(n) (n).begin(),(n).end()
#define inf 0x3f3f3f3f
#define int long long
#define endl '\n'
#define pii pair<int,int>
#define mem(a,val) memset(a,val,sizeof(a))
#define mkp make_pair
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

const int N = 1e5+5;

int T, n;
char mat[505][505];

signed main(void)
{
    io;
    cin >> T;
    while(T--){
        cin >> n;
        mem(mat, '\0');
        for(int i = 0; i < n; i++) cin >> mat[i];
        array<int, 2> a[3];
        a[0][0] = a[1][0] = a[2][0] = 0;
        a[0][1] = 0; a[1][1] = 1; a[2][1] = 2;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(mat[i][j] == 'X')
                    a[(i+j)%3][0]++;
            }
        }
        sort(a, a+3);
        int t = a[0][1];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(mat[i][j] == 'X' && (i+j) % 3 == t){
                    mat[i][j] = 'O';
                }
            }
        }
        for(int i = 0; i < n; i++)
            cout << mat[i] << '\n';
    }
}
