#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

template<typename T>
using line = std::vector<T>;
template<typename T>
using grid = std::vector<line<T>>;

using chline = line<char>;
using chgrid = grid<char>;

// Saw the whole "simple answer" thing, but didn't figure out the colouring :(
// Thought we had to do some counting afterall, since there is a case with corner that I didn't understand how to solve
// Namely, this one:
// XXX
// ..X
// ..X
int main()
{
	int t;
	std::cin >> t;

	for (int _ = 0; _ < t; _++)
	{
		int n;
		std::cin >> n;

		chgrid g = chgrid(n, chline(n, '0'));

		std::vector<int> colcnt = {0, 0, 0};

		int col_start = 0;
		for (chline& l: g)
		{
			col_start = (col_start + 1) % 3;
			int col = col_start;
			for (char& v: l)
			{
				std::cin >> v;
				colcnt[col] += (v == 'X');
				col = (col + 1) % 3;
			}
		}

		int min_color = std::distance(colcnt.begin(), std::min_element(colcnt.begin(), colcnt.end()));

		col_start = 0;
		for (chline& l: g)
		{
			col_start = (col_start + 1) % 3;
			int col = col_start;
			for (char& v: l)
			{
				if (v == 'X' && col == min_color)
				{
					v = 'O';
				}
				std::cout << v;
				col = (col + 1) % 3;
			}
			std::cout << std::endl;
		}
	}
}
