#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        vector<string> grid(n, string(n, ' '));
        int cnt[3] {};
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                cin >> grid[i][j];
                if (grid[i][j] == 'X') ++cnt[(i+j)%3];
            }
        }
        int r = 0;
        for (int i = 1; i <= 2; ++i) {
            if (cnt[i] < cnt[r]) r = i;
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (grid[i][j] == 'X' && (i+j)%3 == r) grid[i][j] = 'O';
            }
            cout << grid[i] << endl;
        }
    }
}
