#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>mp;
void splitarray(vector<int>vec)
{
    int maxx,minn;
    int i;
    ll sum=0;
    for(i=0;i<vec.size();i++)
    {
        sum+=vec[i];
    }
    mp[sum]=1;
    maxx=*max_element(vec.begin(),vec.end());
    minn=*min_element(vec.begin(),vec.end());
    if(maxx==minn)
    {
        return;
    }
    vector<int>left;
    vector<int>right;
    int mid=(maxx+minn)/2;
    for(i=0;i<vec.size();i++)
    {
        if(vec[i]<=mid)
        {
            left.push_back(vec[i]);
        }
        else
        {
            right.push_back(vec[i]);
        }
    }
    splitarray(left);
    splitarray(right);
}
void solve()
{
   int i,n,j;
   cin>>n;
   char ar[n][n];
   int inx[3]={0,0,0};
   for(i=0;i<n;i++)
   {
       for(j=0;j<n;j++)
       {
           cin>>ar[i][j];
           if(ar[i][j]=='X')
           {
               inx[(i+j)%3]++;
           }
       }
   }
   int minn=INT_MAX;
   int tem;
   for(i=0;i<3;i++)
   {
    if(minn>inx[i])
    {
        minn=inx[i];
        tem=i;
    }
   }
 for(i=0;i<n;i++)
   {
       for(j=0;j<n;j++)
       {
           if(ar[i][j]=='X'&&((i+j)%3)==tem)
           {
               ar[i][j]='O';
           }
       }
   }
    for(i=0;i<n;i++)
   {
       for(j=0;j<n;j++)
       {
           cout<<ar[i][j];
       }
       cout<<endl;
   }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc;
    cin>>tc;
    while(tc--)
    {
        solve();
    }
   //solve();
    return 0;
}
