#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vp;
typedef long double db;
#define INF 1e15
#define EPS 1e-9
#define ALL(x) x.begin() , x.end()
#define ALLR(x) x.rbegin() , x.rend()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
const double PI = acos(-1.0);



int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	ll t;
	cin >> t;
	while(t--){
		ll n, x, k, y, limit = 0, xs = 0;
		cin >> n;
		char g[n][n], aux[n][n];
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++){
				cin >> g[i][j];
				if(g[i][j] == 'X')xs++;
			}
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				aux[i][j] = g[i][j];
		for(int i = 0; i < n; i++)
		{
			for(int j = 0; j < n; j++)
			{
				if(g[i][j] == 'X' && (i + j % 3) % 3 == 2)
				{
					bool o = 0;
					ll cont = 0, maxi = 0;
					for(int a = min(ll(i) + 2, n-1); a > i - 3 && a >= 0; a--){
						if(g[a][j] == 'X')cont++;
						else cont = 0;
						maxi = max(cont, maxi);
					}
					if(maxi >= 3)o = 1;
					cont = 0; maxi = 0;
					for(int a = min(ll(j) + 2, n-1); a > j - 3 && a >= 0; a--){
						if(g[i][a] == 'X')cont++;
						else cont = 0;
						maxi = max(cont, maxi);
					}
					if(maxi >= 3)o = 1;
					
					if(o)
					{
						g[i][j] = 'O';
						limit++;
					}
				}
			}
		}
		if(limit > xs / 3)
		{
			limit = 0;
			for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				g[i][j] = aux[i][j];
			for(int i = 0; i < n; i++)
			{
				for(int j = 0; j < n; j++)
				{
					if(g[i][j] == 'X' && (i + j % 3) % 3 == 1)
					{
						bool o = 0;
						ll cont = 0, maxi = 0;
						for(int a = min(ll(i) + 2, n-1); a > i - 3 && a >= 0; a--){
							if(g[a][j] == 'X')cont++;
							else cont = 0;
							maxi = max(cont, maxi);
						}
						if(maxi >= 3)o = 1;
						cont = 0; maxi = 0;
						for(int a = min(ll(j) + 2, n-1); a > j - 3 && a >= 0; a--){
							if(g[i][a] == 'X')cont++;
							else cont = 0;
							maxi = max(cont, maxi);
						}
						if(maxi >= 3)o = 1;
						
						if(o)
						{
							g[i][j] = 'O';
							limit++;
						}
					}
				}
			}

		}
		if(limit > xs / 3)
		{
			limit = 0;
			for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				g[i][j] = aux[i][j];
			for(int i = 0; i < n; i++)
			{
				for(int j = 0; j < n; j++)
				{
					if(g[i][j] == 'X' && (i + j % 3) % 3 == 0)
					{
						bool o = 0;
						ll cont = 0, maxi = 0;
						for(int a = min(ll(i) + 2, n-1); a > i - 3 && a >= 0; a--){
							if(g[a][j] == 'X')cont++;
							else cont = 0;
							maxi = max(cont, maxi);
						}
						if(maxi >= 3)o = 1;
						cont = 0; maxi = 0;
						for(int a = min(ll(j) + 2, n-1); a > j - 3 && a >= 0; a--){
							if(g[i][a] == 'X')cont++;
							else cont = 0;
							maxi = max(cont, maxi);
						}
						if(maxi >= 3)o = 1;
						
						if(o)
						{
							g[i][j] = 'O';
							limit++;
						}
					}
				}
			}

		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cout <<  g[i][j];
			}cout << "\n";
		}

		
	}
	

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}