The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version.

Errichto gave Monogon the following challenge in order to intimidate him from taking his top contributor spot on Codeforces.

In a Tic-Tac-Toe grid, there are n rows and n columns. Each cell of the grid is either empty or contains a token. There are two types of tokens: X and O. If there exist three tokens of the same type consecutive in a row or column, it is a winning configuration. Otherwise, it is a draw configuration.

<image> The patterns in the first row are winning configurations. The patterns in the second row are draw configurations. 

In an operation, you can change an X to an O, or an O to an X. Let k denote the total number of tokens in the grid. Your task is to make the grid a draw in at most ⌊ k/3⌋ (rounding down) operations.

You are not required to minimize the number of operations.

Input

The first line contains a single integer t (1≤ t≤ 100) — the number of test cases.

The first line of each test case contains a single integer n (1≤ n≤ 300) — the size of the grid.

The following n lines each contain a string of n characters, denoting the initial grid. The character in the i-th row and j-th column is '.' if the cell is empty, or it is the type of token in the cell: 'X' or 'O'.

It is guaranteed that not all cells are empty.

In the easy version, the character 'O' does not appear in the input.

The sum of n across all test cases does not exceed 300.

Output

For each test case, print the state of the grid after applying the operations.

We have proof that a solution always exists. If there are multiple solutions, print any.

Example

Input


3
3
.X.
XXX
.X.
6
XX.XXX
XXXXXX
XXX.XX
XXXXXX
XX.X.X
XXXXXX
5
XXX.X
.X..X
XXX.X
..X..
..X..


Output


.X.
XOX
.X.
XX.XXO
XOXXOX
OXX.XX
XOOXXO
XX.X.X
OXXOXX
XOX.X
.X..X
XXO.O
..X..
..X..

Note

In the first test case, there are initially three 'X' consecutive in the second row and the second column. By changing the middle token to 'O' we make the grid a draw, and we only changed 1≤ ⌊ 5/3⌋ token.

In the second test case, we change only 9≤ ⌊ 32/3⌋ tokens, and there does not exist any three 'X' or 'O' consecutive in a row or column, so it is a draw.

In the third test case, we change only 3≤ ⌊ 12/3⌋ tokens, and the resulting grid is a draw.
import java.io.*;import java.util.*;import java.math.*;
public class Main
{
	static long mod=1000000007l;
    static int max=Integer.MAX_VALUE,min=Integer.MIN_VALUE;
    static long maxl=Long.MAX_VALUE,minl=Long.MIN_VALUE;
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static StringBuilder sb;
    
    static public void main(String[] args)throws Exception
    {
    	st=new StringTokenizer(br.readLine());
    	int t=i();
    	sb=new StringBuilder(1000000);
    	o:
    	while(t-->0)
    		
    	{
    		int n=i();
    		char ar[][]=arc(n,n);
    		int cc=0;
    		for(int x=0;x<n;x++)
    		{
    			for(int y=0;y<n;y++)
    			{
    				if(ar[x][y]=='X')cc++;
    			}
    		}
    		int i=-1*(n-1);
    		int j=(n-1);
    		int a[]=new int[2*n-1];
    		int v=i;
    		int ii=-1;
    		while(v<=j)
    		{
    			a[++ii]=v;
    			v++;
    		}
    		//p(a);
    		int c=0;
    		int l=cc/3;
    		HashSet<Integer> h=new HashSet<>();
    		for(int x=i;x<=j;x+=3)
    		{
    			h.add(x);
    		}
    		char kk[][]=new char[n][n];
    		for(int x=0;x<n;x++)
    		{
    			for(int y=0;y<n;y++)
    			{
    				kk[x][y]=ar[x][y];
    			}
    		}
    		for(int x=0;x<n;x++)
    		{
    			for(int y=0;y<n;y++)
    			{
    				if(f(x,y,kk)&&h.contains(x-y))
    					{
    					if(ar[x][y]=='X')kk[x][y]='O';
    					else kk[x][y]='X';
    					c++;
    					}
    			}
    		}
    		int q=0;
    		for(int x=0;x<=n-3;x++)
    		{
    			for(int y=0;y<=n-3;y++)
    			{
    				if(kk[x][y]==kk[x][y+1]&&kk[x][y+2]==kk[x][y+1]&&kk[x][y]!='.')
    				{
    					q=1;
    					break;
    				}
    				if(kk[x][y]==kk[x+1][y]&&kk[x+1][y]==kk[x+2][y]&&kk[x][y]!='.')
    				{
    					q=1;
    					break;
    				}
    			}
    		}
    		if(c<=l&&q==0)
    		{
    			s(kk);
    			continue o;
    		}
    		
    		
    		c=0;
    		h=new HashSet<>();
    		for(int x=i+1;x<=j;x+=3)
    		{
    			h.add(x);
    		}
    		kk=new char[n][n];
    		for(int x=0;x<n;x++)
    		{
    			for(int y=0;y<n;y++)
    			{
    				kk[x][y]=ar[x][y];
    			}
    		}
    		for(int x=0;x<n;x++)
    		{
    			for(int y=0;y<n;y++)
    			{
    				if(f(x,y,kk)&&h.contains(x-y))
    					{
    					if(ar[x][y]=='X')kk[x][y]='O';
    					else kk[x][y]='X';
    					c++;
    					}
    			}
    		}
    		q=0;
    		for(int x=0;x<=n-3;x++)
    		{
    			for(int y=0;y<=n-3;y++)
    			{
    				if(kk[x][y]==kk[x][y+1]&&kk[x][y+2]==kk[x][y+1]&&kk[x][y]!='.')
    				{
    					q=1;
    					break;
    				}
    				if(kk[x][y]==kk[x+1][y]&&kk[x+1][y]==kk[x+2][y]&&kk[x][y]!='.')
    				{
    					q=1;
    					break;
    				}
    			}
    		}
    		if(c<=l&&q==0)
    		{
    			s(kk);
    			continue o;
    		}
    		
    		c=0;
    		h=new HashSet<>();
    		for(int x=i+2;x<=j;x+=3)
    		{
    			h.add(x);
    		}
    		kk=new char[n][n];
    		for(int x=0;x<n;x++)
    		{
    			for(int y=0;y<n;y++)
    			{
    				kk[x][y]=ar[x][y];
    			}
    		}
    		for(int x=0;x<n;x++)
    		{
    			for(int y=0;y<n;y++)
    			{
    				if(f(x,y,kk)&&h.contains(x-y))
    					{
    					if(ar[x][y]=='X')kk[x][y]='O';
    					else kk[x][y]='X';
    					c++;
    					}
    			}
    		}
    		s(kk);
    	}
    	p(sb);
    }
    
    static boolean f(int x,int y,char ar[][])
    {
    	if(ar[x][y]!='.'&&x!=0&&ar[x-1][y]==ar[x][y]&&x!=ar.length-1&&ar[x+1][y]==ar[x][y])return true;
    	if(ar[x][y]!='.'&&y!=0&&ar[x][y-1]==ar[x][y]&&y!=ar.length-1&&ar[x][y+1]==ar[x][y])return true;
    	if(ar[x][y]!='.'&&x>=2&&ar[x][y]==ar[x-1][y]&&ar[x][y]==ar[x-2][y])return true;
    	if(ar[x][y]!='.'&&x<=ar.length-3&&ar[x][y]==ar[x+1][y]&&ar[x][y]==ar[x+2][y])return true;
    	
    	if(ar[x][y]!='.'&&y>=2&&ar[x][y]==ar[x][y-1]&&ar[x][y]==ar[x][y-1])return true;
    	if(ar[x][y]!='.'&&y<=ar.length-3&&ar[x][y]==ar[x][y+1]&&ar[x][y]==ar[x][y+2])return true;
    	return false;
    }
    
    
    static void s(String s){sb.append(s);}
    static void s(int s){sb.append(s);}
    static void s(long s){sb.append(s);}
    static void s(char s){sb.append(s);}
    static void s(double s){sb.append(s);}
    static void ss(){sb.append(' ');}
    static void sl(String s){sb.append(s);sb.append("\n");}
    static void sl(int s){sb.append(s);sb.append("\n");}
    static void sl(long s){sb.append(s);sb.append("\n");}
    static void sl(char s){sb.append(s);sb.append("\n");}
    static void sl(double s){sb.append(s);sb.append("\n");}
    static void sl(){sb.append("\n");}
    static int max(int a,int b){return a>b?a:b;}
    static int min(int a,int b){return a<b?a:b;}
    static int abs(int a){return Math.abs(a);}
    static long max(long a,long b){return a>b?a:b;}
    static long min(long a,long b){return a<b?a:b;}
    static long abs(long a){return Math.abs(a);}
    static int sq(int a){return (int)Math.sqrt(a);}
    static long sq(long a){return (long)Math.sqrt(a);}
    static int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
    static boolean pa(String s,int i,int j)
    {
    	while(i<j)if(s.charAt(i++)!=s.charAt(j--))return false;
    	return true;
    }
    static int ncr(int n,int c,long m)
    {
        long a=1l;
        for(int x=n-c+1;x<=n;x++)a=((a*x)%m);
        long b=1l;
        for(int x=2;x<=c;x++)b=((b*x)%m);
        return (int)((a*(mul((int)b,m-2,m)%m))%m);
    }
    static boolean[] sieve(int n)
    {
        boolean bo[]=new boolean[n+1];
        bo[0]=true;bo[1]=true;
        for(int x=4;x<=n;x+=2)bo[x]=true;
        for(int x=3;x*x<=n;x+=2)if(!bo[x])for(int y=x*x;y<=n;y+=x)bo[y]=true;
        return bo;
    }
    static int[] fac(int n)
    {
        int bo[]=new int[n+1];
        for(int x=1;x<=n;x++)for(int y=x;y<=n;y+=x)bo[y]++;
        return bo;
    }
    static long mul(long a,long b,long m) 
    {
        long r=1l;
        a%=m;  
        while(b>0)
        {
            if((b&1)==1)r=(r*a)%m; 
            b>>=1;
            a=(a*a)%m;  
        } 
        return r; 
    }
    static int i()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }
    static long l()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }
    static String s()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
    static double d()throws IOException
    {
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        return Double.parseDouble(st.nextToken());
    }
    static void p(Object p){System.out.print(p);}
    static void p(String p){System.out.print(p);}
    static void p(int p){System.out.print(p);}
    static void p(double p){System.out.print(p);}
    static void p(long p){System.out.print(p);}
    static void p(char p){System.out.print(p);}
    static void p(boolean p){System.out.print(p);}
    static void pl(Object p){System.out.println(p);}
    static void pl(String p){System.out.println(p);}
    static void pl(int p){System.out.println(p);}
    static void pl(char p){System.out.println(p);}
    static void pl(double p){System.out.println(p);}
    static void pl(long p){System.out.println(p);}
    static void pl(boolean p){System.out.println(p);}
    static void pl(){System.out.println();}
    static void s(int a[])
    {
    	for(int e:a)
    	{
    		sb.append(e);
    		sb.append(' ');
    	}
    	sb.append("\n");
    }
    static void s(int ar[][])
    {
    	for(int a[]:ar)
    	{
	    	for(int e:a)
	    	{
	    		sb.append(e);
	    		sb.append(' ');
	    	}
	    	sb.append("\n");
    	}
    }
    static void s(char a[])
    {
    	for(char e:a)
    	{
    		sb.append(e);
    		sb.append(' ');
    	}
    	sb.append("\n");
    }
    static void s(char ar[][])
    {
    	for(char a[]:ar)
    	{
	    	for(char e:a)
	    	{
	    		sb.append(e);
	    		
	    	}
	    	sb.append("\n");
    	}
    }
    static int[] ari(int n)throws IOException
    {
        int ar[]=new int[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Integer.parseInt(st.nextToken());
        return ar;
    }
    static int[][] ari(int n,int m)throws IOException
    {
        int ar[][]=new int[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Integer.parseInt(st.nextToken());
        }
        return ar;
    }
    static long[] arl(int n)throws IOException
    {
        long ar[]=new long[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=Long.parseLong(st.nextToken());
        return ar;
    }
    static long[][] arl(int n,int m)throws IOException
    {
        long ar[][]=new long[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Long.parseLong(st.nextToken());
        }
        return ar;
    }
    static String[] ars(int n)throws IOException
    {
        String ar[]=new String[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++) ar[x]=st.nextToken();
        return ar;
    }
    static double[] ard(int n)throws IOException
    {
        double ar[]=new double[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=Double.parseDouble(st.nextToken());
        return ar;
    }
    static double[][] ard(int n,int m)throws IOException
    {
        double ar[][]=new double[n][m];
        for(int x=0;x<n;x++)
        {
        	if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
            for(int y=0;y<m;y++)ar[x][y]=Double.parseDouble(st.nextToken());
        }
        return ar;
    }
    static char[] arc(int n)throws IOException
    {
        char ar[]=new char[n];
        if(!st.hasMoreTokens())st=new StringTokenizer(br.readLine());
        for(int x=0;x<n;x++)ar[x]=st.nextToken().charAt(0);
        return ar;
    }
    static char[][] arc(int n,int m)throws IOException
    {
        char ar[][]=new char[n][m];
        for(int x=0;x<n;x++)
        {
            String s=br.readLine();
            for(int y=0;y<m;y++)ar[x][y]=s.charAt(y);
        }
        return ar;
    }
    static void p(int ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(int a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(int ar[][])
    {
    	StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(int a[]:ar)
        {
            for(int aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(long ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(long a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(long ar[][])
    {
    	StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(long a[]:ar)
        {
            for(long aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(String ar[])
    {
    	int c=0;
    	for(String s:ar)c+=s.length()+1;
        StringBuilder sb=new StringBuilder(c);
        for(String a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(double a:ar)
        {
        	sb.append(a);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(double ar[][])
    {
    	StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(double a[]:ar)
        {
            for(double aa:a)
            {
            	sb.append(aa);
            	sb.append(' ');
            }
            sb.append("\n");
        }
        p(sb);
    }
    static void p(char ar[])
    {
        StringBuilder sb=new StringBuilder(2*ar.length);
        for(char aa:ar)
        {
        	sb.append(aa);
        	sb.append(' ');
        }
        System.out.println(sb);
    }
    static void p(char ar[][])
    {
        StringBuilder sb=new StringBuilder(2*ar.length*ar[0].length);
        for(char a[]:ar)
        {
            for(char aa:a)
            {
            	sb.append(aa);
            	
            }
            sb.append("\n");
        }
        p(sb);
    }
}