#include <bits/stdc++.h>
using namespace std;


class Task {
 private:
    int n;
    vector<string>s;
    void Read() {
        cin >> n;
        s.resize(n);
        for(auto &e : s) {
            cin >> e;
        }
    }
 
    void Solve() {
        vector<int>v(3,0);
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < n; ++j) {
                if(s[i][j] == 'X'){
                    v[(i + j)%3]++;
                }
            }
        }
        int id = min_element(v.begin(), v.end()) - v.begin();
        for(int i = 0;i < n;++i) {
            for(int j = 0;j < n;++j) {
                if(s[i][j] == 'X' and (i + j)%3 == id){
                    s[i][j] = 'O';
                }
            }
            cout << s[i] << "\n";
        }
    }
 
 public:
    void Perform() {
        Read();
        Solve();
    }
};
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tc;
    cin >> tc;
    for(int tt = 1; tt <= tc; ++tt) {
        Task t;
        t.Perform();
    }
  return 0;
}