Codeforces Global Round 12
C2
Errich-Tac-Toe (Hard Version)
Codeforces
2300
原题
← C1D →
翻译中…

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 $\lfloor \frac{k}{3}\rfloor$ (rounding down) operations.

翻译中…

You are not required to minimize the number of operations.

翻译中…

Input

翻译中…

The first line contains a single integer $t$ ($1\le t\le 100$) — the number of test cases.

翻译中…

The first line of each test case contains a single integer $n$ ($1\le n\le 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.

翻译中…

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.

翻译中…

Note

翻译中…

In the first test case, there are initially three 'O' consecutive in the second row and the second column. By changing the middle token to 'X' we make the grid a draw, and we only changed $1\le \lfloor 5/3\rfloor$ token.

翻译中…

In the second test case, the final grid is a draw. We only changed $8\le \lfloor 32/3\rfloor$ tokens.

翻译中…

In the third test case, the final grid is a draw. We only changed $7\le \lfloor 21/3\rfloor$ tokens.

翻译中…

样例

Input #1
3
3
.O.
OOO
.O.
6
XXXOOO
XXXOOO
XX..OO
OO..XX
OOOXXX
OOOXXX
5
.OOO.
OXXXO
OXXXO
OXXXO
.OOO.
Output #1
.O.
OXO
.O.
OXXOOX
XOXOXO
XX..OO
OO..XX
OXOXOX
XOOXXO
.OXO.
OOXXO
XXOXX
OXXOO
.OXO.
InputCopy OutputCopy
题目信息
题号
1450C2
时间限制
1 s
内存限制
256 MB
标签
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。