#include<bits/stdc++.h> 
using namespace std; 
#define int long long
void solve(); 
int32_t main() 
{ 
ios_base::sync_with_stdio(false);cin.tie(NULL); 

#ifndef ONLINE_JUDGE 
freopen("input.txt", "r", stdin); 
freopen("error.txt", "w", stderr); 
freopen("output.txt", "w", stdout); 
#endif 

int t=1; 
cin>>t; 
while(t--) 
{
    solve();
}

cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
return 0; 
} 
void solve() 
{
	int n;cin>>n;
	vector<string> a(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}       

	int r=0;
	int g=0;
	int b=0;


	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i][j]=='X')
			{
				if((i+j)%3==0)
				{
					r++;
				}
				else if((i+j)%3==1)
				{
					g++;
				} 
				else
				{
					b++;
				}
			}
		}
	}

	int c = min(r,min(g,b));
	if(c==r)
	{
		c = 0; 
	}
	else if(c==g)
	{
		c = 1; 
	}
	else 
	{
		c=2;
	}

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i][j]=='X')
			{
				if((i+j)%3==c)
				{
					a[i][j] = 'O';
				}
			}

			cout<<a[i][j];

		}
		cout<<endl;
	}

}