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.

/**
 * Date: 06 Dec, 2020
 * Link: https://codeforces.com/contest/1450/problem/C
 * 
 * @author: Prasad Chaudhari
 * @linkedIn: https://www.linkedin.com/in/prasad-chaudhari-841655a6/
 * @git: https://github.com/Prasad-Chaudhari
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;

public class C_1450 {

    public static void main(String[] args) throws IOException {
        FastIO in = new FastIO(args);
        int t = in.ni();
        while (t-- > 0) {
            int n = in.ni();
            int a[][] = new int[n][n];
            for (int i = 0; i < n; i++) {
                char c[] = in.next().toCharArray();
                for (int j = 0; j < n; j++)
                    if (c[j] == 'X')
                        a[i][j] = 1;
                    else if (c[j] == 'O')
                        a[i][j] = 2;
            }
            // for (int i = 0; i < n; i++) {
            //     for (int j = 0; j < n; j++) {
            //         System.out.print(a[i][j]);
            //     }
            //     System.out.println();
            // }
            int k = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    k += a[i][j] != 0 ? 1 : 0;
                }
            }
            int ans[][] = new int[0][0];
            for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
            ans = ans(a, i, j, k);
            if (ans.length != 0)
            i = j = 3;
            }
            }
            // ans(a, 2, 0, k);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    in.print(c(ans[i][j]) + "");
                }
                in.println("");
            }
        }
        in.bw.flush();
    }

    static private int[][] ans(int a[][], int x_diff, int o_diff, int k) {
        int n = a.length;
        int b[][] = new int[n][];
        for (int i = 0; i < n; i++) {
            b[i] = Arrays.copyOf(a[i], n);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (((i - j % 3) + 3) % 3 == x_diff && b[i][j] == 1) {
                    boolean p = false;
                    p |= get(i, j, 0, -1, b) && get(i, j, 0, -2, b);
                    p |= get(i, j, 0, 1, b) && get(i, j, 0, 2, b);
                    p |= get(i, j, -1, 0, b) && get(i, j, -2, 0, b);
                    p |= get(i, j, 1, 0, b) && get(i, j, 2, 0, b);
                    p |= get(i, j, -1, 0, b) && get(i, j, 1, 0, b);
                    p |= get(i, j, 0, -1, b) && get(i, j, 0, 1, b);
                    if (p) {
                        b[i][j] = 2;
                    }
                }
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (((i - j % 3) + 3) % 3 == o_diff && b[i][j] == 2) {
                    boolean p = false;
                    p |= get(i, j, 0, -1, b) && get(i, j, 0, -2, b);
                    p |= get(i, j, 0, 1, b) && get(i, j, 0, 2, b);
                    p |= get(i, j, -1, 0, b) && get(i, j, -2, 0, b);
                    p |= get(i, j, 1, 0, b) && get(i, j, 2, 0, b);
                    p |= get(i, j, -1, 0, b) && get(i, j, 1, 0, b);
                    p |= get(i, j, 0, -1, b) && get(i, j, 0, 1, b);
                    if (p) {
                        b[i][j] = 1;
                    }
                }
            }
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (b[i][j] != 0) {
                    boolean p = false;
                    p |= get(i, j, 0, -1, b) && get(i, j, 0, -2, b);
                    p |= get(i, j, 0, 1, b) && get(i, j, 0, 2, b);
                    p |= get(i, j, -1, 0, b) && get(i, j, -2, 0, b);
                    p |= get(i, j, 1, 0, b) && get(i, j, 2, 0, b);
                    p |= get(i, j, -1, 0, b) && get(i, j, 1, 0, b);
                    p |= get(i, j, 0, -1, b) && get(i, j, 0, 1, b);
                    if (p) {
                        count += k;
                    } else {
                        count += a[i][j] != b[i][j] ? 1 : 0;
                    }
                }
            }
        }
        // System.out.println(x_diff + " " + o_diff);
        // for (int i = 0; i < n; i++) {
        //     for (int j = 0; j < n; j++)
        //         System.out.print(c(b[i][j]));
        //     System.out.println();
        // }
        // System.out.println();
        if (count <= k / 3) {
            return b;
        } else {
            return new int[0][0];
        }
    }

    static char c(int a) {
        return a == 0 ? '.' : (a == 1) ? 'X' : 'O';
    }

    static private boolean get(int i, int j, int a, int b, int[][] c) {
        if (i + a >= 0 && i + a < c.length && j + b >= 0 && j + b < c.length) {
            return c[i][j] == c[i + a][j + b];
        }
        return false;
    }

    static class Data implements Comparable<Data> {

        int a, b;

        public Data(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(Data o) {
            if (a == o.a) {
                return Integer.compare(b, o.b);
            }
            return Integer.compare(a, o.a);
        }

        public static void sort(int a[]) {
            Data d[] = new Data[a.length];
            for (int i = 0; i < a.length; i++) {
                d[i] = new Data(a[i], 0);
            }
            Arrays.sort(d);
            for (int i = 0; i < a.length; i++) {
                a[i] = d[i].a;
            }
        }
    }

    static class FastIO {

        private final BufferedReader br;
        private final BufferedWriter bw;
        private String s[];
        private int index;

        public FastIO(String[] args) throws IOException {
            if (args.length > 1) {
                br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(args[0]))));
                bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(args[1]))));
            } else {
                br = new BufferedReader(new InputStreamReader(System.in));
                bw = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
            }
            s = br.readLine().split(" ");
            index = 0;
        }

        public int ni() throws IOException {
            return Integer.parseInt(nextToken());
        }

        public double nd() throws IOException {
            return Double.parseDouble(nextToken());
        }

        public long nl() throws IOException {
            return Long.parseLong(nextToken());
        }

        public String next() throws IOException {
            return nextToken();
        }

        public String nli() throws IOException {
            try {
                return br.readLine();
            } catch (IOException ex) {

            }
            return null;
        }

        public int[] gia(int n) throws IOException {
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }

        public int[] gia(int n, int start, int end) throws IOException {
            validate(n, start, end);
            int a[] = new int[n];
            for (int i = start; i < end; i++) {
                a[i] = ni();
            }
            return a;
        }

        public double[] gda(int n) throws IOException {
            double a[] = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }

        public double[] gda(int n, int start, int end) throws IOException {
            validate(n, start, end);
            double a[] = new double[n];
            for (int i = start; i < end; i++) {
                a[i] = nd();
            }
            return a;
        }

        public long[] gla(int n) throws IOException {
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }

        public long[] gla(int n, int start, int end) throws IOException {
            validate(n, start, end);
            long a[] = new long[n];
            for (int i = start; i < end; i++) {
                a[i] = nl();
            }
            return a;
        }

        public void print(String s) throws IOException {
            bw.write(s);
        }

        public void println(String s) throws IOException {
            bw.write(s);
            bw.newLine();
        }

        public void print(int s) throws IOException {
            bw.write(s + "");
        }

        public void println(int s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(long s) throws IOException {
            bw.write(s + "");
        }

        public void println(long s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        public void print(double s) throws IOException {
            bw.write(s + "");
        }

        public void println(double s) throws IOException {
            bw.write(s + "");
            bw.newLine();
        }

        private String nextToken() throws IndexOutOfBoundsException, IOException {
            if (index == s.length) {
                s = br.readLine().split(" ");
                index = 0;
            }
            return s[index++];
        }

        private void validate(int n, int start, int end) {
            if (start < 0 || end >= n) {
                throw new IllegalArgumentException();
            }
        }
    }
}
