#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i,a,b)  for(int i = a; i < b; i++)
#define Rep(i,a,b)  for(int i = a, i <= b; i++)
#define int         long long
#define pii         pair<int,int>
#define vi          vector <int>
#define mod         1000000007
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x)  __builtin_ctzll(x)   //no of zero bits befor the first set bits
#define inf         1e18
#define ps(x,y)     fixed<<setprecision(y)<<x

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }

void start()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

}


void solve(int no,int n)
{
    for(int i=0;i<n;i++)
    {
        cout<<no<<" ";
    }
}
int32_t main()
{
    start();
    int t=1;;
     cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        char a[n][n];
        int count[3]={0};
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                cin>>a[i][j];
                if(a[i][j]=='X')
                count[(i+j)%3]++;
            }
        }

        int value=min_element(count,count+3)-count;
       for(int i=0;i<n;i++)
       {
            for(int j=0;j<n;j++)
            {
                if(a[i][j]=='X' and (i+j)%3==value)
                {
                    a[i][j]='O';
                }
                cout<<a[i][j];
            }
            cout<<endl;
       }


    }
}