#include <bits/stdc++.h>

void solve() {
  int n;
  std::cin >> n;

  std::vector<std::string> board(n);
  for (auto &row : board) {
    std::cin >> row;
  }

  int cnt[2][3] = {};
  for (auto i = 0; i < n; ++i) {
    for (auto j = 0; j < n; ++j) {
      if (board[i][j] == 'O') {
        cnt[0][(i + j) % 3] += 1;
      }
      if (board[i][j] == 'X') {
        cnt[1][(i + j) % 3] += 1;
      }
    }
  }

  int x = 0;
  for (int i = 0; i < 3; ++i) {
    if (cnt[0][i] + cnt[1][(i + 1) % 3] < cnt[0][x] + cnt[1][(x + 1) % 3]) {
      x = i;
    }
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (board[i][j] == 'O' && (i + j) % 3 == x) {
        board[i][j] = 'X';
      }
      if (board[i][j] == 'X' && (i + j) % 3 == (x + 1) % 3) {
        board[i][j] = 'O';
      }
    }
  }

  for (const auto &row : board) {
    std::cout << row << std::endl;
  }
}

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);

  int t = 1;
  std::cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}