#include <cstdio>
#include <cstring>
const int MAXN = 300;
int T , n , k , cnt; char str[ MAXN + 5 ][ MAXN + 5 ] , Ans[ MAXN + 5 ][ MAXN + 5 ];
int main( ) {
scanf("%d",&T);
while( T -- ) {
scanf("%d",&n); k = 0;
for( int i = 1 ; i <= n ; i ++ ) scanf("%s", str[ i ] + 1 );
for( int i = 1 ; i <= n ; i ++ ) for( int j = 1 ; j <= n ; j ++ ) k += str[ i ][ j ] != '.';
cnt = 0; memcpy( Ans , str , sizeof( str ) );
for( int i = 1 ; i <= n ; i ++ )
for( int j = 1 ; j <= n ; j ++ ) if( str[ i ][ j ] != '.' ) {
if( ( i + j ) % 3 == 0 ) Ans[ i ][ j ] = 'X' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
if( ( i + j ) % 3 == 1 ) Ans[ i ][ j ] = 'O' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
}
if( cnt <= k / 3 ) {
for( int i = 1 ; i <= n ; i ++ ) puts( Ans[ i ] + 1 );
continue;
}
cnt = 0; memcpy( Ans , str , sizeof( str ) );
for( int i = 1 ; i <= n ; i ++ )
for( int j = 1 ; j <= n ; j ++ ) if( str[ i ][ j ] != '.' ) {
if( ( i + j ) % 3 == 1 ) Ans[ i ][ j ] = 'X' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
if( ( i + j ) % 3 == 2 ) Ans[ i ][ j ] = 'O' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
}
if( cnt <= k / 3 ) {
for( int i = 1 ; i <= n ; i ++ ) puts( Ans[ i ] + 1 );
continue;
}
cnt = 0; memcpy( Ans , str , sizeof( str ) );
for( int i = 1 ; i <= n ; i ++ )
for( int j = 1 ; j <= n ; j ++ ) if( str[ i ][ j ] != '.' ) {
if( ( i + j ) % 3 == 2 ) Ans[ i ][ j ] = 'X' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
if( ( i + j ) % 3 == 0 ) Ans[ i ][ j ] = 'O' , cnt += Ans[ i ][ j ] != str[ i ][ j ];
}
if( cnt <= k / 3 ) {
for( int i = 1 ; i <= n ; i ++ ) puts( Ans[ i ] + 1 );
continue;
}
}
return 0;
}