
// Problem: C1. Errich-Tac-Toe (Easy Version)
// Contest: Codeforces - Codeforces Global Round 12
// URL: https://codeforces.com/contest/1450/problem/C1
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define F(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end()

using ld = long double;
using vi = vector <int>;
using mi = map <int, int>;
using pii = pair <int, int>;

const int N = 100005;
const int MOD = 1e9 + 7;

#define show(arr) { for (auto x: arr) cout << x ; cout << '\n'; }
#define show_(arr, n) F(i, n) show(arr[i])

void solve() {
	
	int n, ans = 0; cin>>n;
   	char a[n][n];
   	F(i, n)F(j, n){
   		cin>>a[i][j];
   	}
   	int cnt[3]={0};
   	F(i, n){
	   	F(j, n){
	   		if(a[i][j]=='X')
	   		cnt[(i+j)%3]++;
	   	}
   	}
   	int z=min_element(cnt,cnt+3)-cnt;
   	F(i, n){
	   	F(j, n){
	   		if((i+j)%3==z && a[i][j]=='X') a[i][j]='O';
	   	}
   	}
   	show_(a, n);
}
int32_t main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);

   int32_t t=1;
   cin >> t;
   while (t--) solve();

   return 0;
}