#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=310;
char s[maxn][maxn];
int n;
bool check(int i,int j){
    if(i-1>=0&&i+1<n&&s[i][j]=='X'&&s[i-1][j]=='X'&&s[i+1][j]=='X') return true;
    if(j-1>=0&&j+1<n&&s[i][j]=='X'&&s[i][j-1]=='X'&&s[i][j+1]=='X') return true;
    if(j+2<n&&s[i][j]=='X'&&s[i][j+1]=='X'&&s[i][j+2]=='X') return true;
    if(j-2>=0&&s[i][j]=='X'&&s[i][j-1]=='X'&&s[i][j-2]=='X') return true;
    if(i+2<n&&s[i][j]=='X'&&s[i+1][j]=='X'&&s[i+2][j]=='X') return true;
    if(i-2>=0&&s[i][j]=='X'&&s[i-1][j]=='X'&&s[i-2][j]=='X') return true;
    return false;
}
char a[maxn][maxn];
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=0;i<n;i++)scanf("%s",s[i]);
        int k=0,cnt=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(s[i][j]=='X')k++;
                a[i][j]=s[i][j];
                if(i%3==j%3&&s[i][j]=='X'&&check(i,j)){
                    a[i][j]='O';
                    cnt++;
                }
            }
        }
        if(cnt<=k/3){
            for(int i=0;i<n;i++){
                a[i][n]=0;
                puts(a[i]);
            }
            continue;
        }
        cnt=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                a[i][j]=s[i][j];
                if((i+1)%3==j%3&&s[i][j]=='X'&&check(i,j)){
                    a[i][j]='O';
                    cnt++;
                }
            }
        }
        if(cnt<=k/3){
            for(int i=0;i<n;i++){
                a[i][n]=0;
                puts(a[i]);
            }
            continue;
        }
        cnt=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                a[i][j]=s[i][j];
                if((i+2)%3==j%3&&s[i][j]=='X'&&check(i,j)){
                    a[i][j]='O';
                    cnt++;
                }
            }
        }
        if(cnt<=k/3){
            for(int i=0;i<n;i++){
                a[i][n]=0;
                puts(a[i]);
            }
            continue;
        }
    }
    return 0;
}