Codeforces Round 1116 (Div. 2)
E
Even If the World Turns
Codeforces
未评级
原题
← DF →

Even If the World TurnsAI (CI翻译)

Now, no matter what anyone says, I am the happiest girl in the world.— Chtholly

This is a run-twice (communication) problem.

At the Fairy Warehouse, Nygglatho prepared an unusual game for Chtholly and Willem.

They would be separated and unable to exchange a single word. Between them there would be only a black-and-white picture — one that Nygglatho could shift, rotate, reflect, or even invert its colors.

Nygglatho saw it as a test of how well they understood each other. Chtholly and Willem perhaps saw only another kind of promise. No matter how the world turned, they would still find the same place.

The two players are Chtholly and Willem. The jury, acting as Nygglatho, first communicates with Chtholly. After Chtholly finishes, the jury communicates with Willem. Chtholly and Willem may agree on the strategy they will use beforehand, but they cannot directly pass information to each other.

In each test case, Nygglatho prepares a black-and-white picture consisting of $n \times n$ cells and chooses a target cell $x$. The rows and columns are numbered from $1$ to $n$.

The picture contains $w$ black cells. It is guaranteed that $\gcd(n,w)=1$.

Nygglatho first shows the picture and the target cell $x$ to Chtholly. Chtholly must choose two cells and swap their colors. The two cells are allowed to be the same. If they are the same, or if they have the same color, the picture does not change. She cannot send Willem any other information.

Swapping colors does not move the target cell.

Nygglatho then secretly transforms the picture. She may perform the following operations any number of times, possibly zero, in any order:

  1. Choose two integers $d_r$ and $d_c$ ($0\le d_r,d_c \lt n$) and cyclically shifts the picture. Every cell $(r,c)$ moves to $\left(\left(r-1+d_r\right)\bmod n+1,\left(c-1+d_c\right)\bmod n+1\right)$;
  2. Rotate the picture clockwise by $90^\circ$. One such rotation moves every cell $(r,c)$ to $(c,n+1-r)$;
  3. Reflect the picture across its vertical axis. Such a reflection moves every cell $(r,c)$ to $(r,n+1-c)$;
  4. Invert all colors. This changes every black cell into a white cell and every white cell into a black cell.

The target cell $x$ undergoes every cyclic shift, rotation, and reflection in exactly the same way as the picture. Color inversions do not move it.

Finally, Nygglatho shows only the resulting picture to Willem. Willem must determine the final position of $x$.

Your program will be run exactly twice on each test. On the first run, it must act as Chtholly. On the second run, it must act as Willem. No information is preserved between the two runs except for the information passed by the jury according to the rules above.

The order of the test cases may be changed between the two runs.

First Run

On the first run, you are Chtholly.

Input

The first line contains the string first, indicating that this is the first run.

After this line, the remaining input has the following format.

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

The first line of each test case contains an integer $n$ ($2 \le n \le 800$) — the height and width of the picture.

Each of the next $n$ lines contains a string of length $n$. The character $\mathtt{\#}$ denotes a black cell, and the character $\mathtt{.}$ denotes a white cell.

The next line contains two integers $r_x$ and $c_x$ ($1 \le r_x,c_x \le n$) — the row and column of the target cell $x$.

Let $w$ be the number of black cells in the picture. It is guaranteed that $\gcd(n,w)=1$.

It is guaranteed that the sum of $n^2$ over all test cases does not exceed $800^2$.

Output

For each test case, output four integers $r_1$, $c_1$, $r_2$, and $c_2$ ($1 \le r_1,c_1,r_2,c_2 \le n$) — the two cells whose colors Chtholly chooses to swap. The two cells are allowed to be the same.

Second Run

On the second run, you are Willem.

Input

The first line contains the string second, indicating that this is the second run.

After this line, the remaining input has the following format.

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

The value of $t$ is the same as on the first run, although the test cases may appear in a different order.

The first line of each test case contains the integer $n$ ($2 \le n \le 800$).

Each of the next $n$ lines contains a string of length $n$, describing the resulting picture after Chtholly's swap and Nygglatho's transformations for the corresponding test case from the first run. Again, $\mathtt{\#}$ denotes a black cell and $\mathtt{.}$ denotes a white cell.

It is guaranteed that the sum of $n^2$ over all test cases does not exceed $800^2$.

Output

For each test case, output two integers $r'_x$ and $c'_x$ ($1 \le r'_x,c'_x \le n$) — the row and column of the target cell after all transformations.

Hacks are disabled in this problem.

Note

The first example shows Chtholly's run for two test cases. The second example shows Willem's run for the same two test cases. The outputs shown for Chtholly's run are just one possible set of valid choices.

In the first test case, Chtholly swaps cells $(1,1)$ and $(4,1)$. Afterwards, the two black cells are at $(2,2)$ and $(4,1)$.

In this example, Nygglatho performs the following transformations.

  • she cyclically shifts the picture one row down and two columns to the right;
  • she rotates the picture clockwise by $90^\circ$ once;
  • she reflects the picture across its vertical axis;

The target moves from $(3,4)$ to $(4,1)$ after the cyclic shift, then to $(1,2)$ after the rotation, and finally to $(1,4)$ after the reflection. The two black cells finally arrive at $(3,5)$ and $(4,3)$, giving exactly the picture in Willem's run. Willem reports the target position $(1,4)$.

In the second test case, Chtholly can choose the same cell, in which case nothing changes. Nygglatho can then also choose to do nothing.

{"titleZh":"即使世界天翻地覆","bodyZh":"现在,无论别人怎么说,我都是世界上最幸福的女孩。—— Chtholly\n\n这是一道运行两次(通信)题。\n\n在妖精仓库中,Nygglatho 为 Chtholly 和 Willem 准备了一场不同寻常的游戏。\n\n他们彼此分开,无法交换哪怕一句话。在他们之间只有一张黑白图片——Nygglatho 可以移动、旋转、翻转这张图片,甚至反转其颜色。\n\nNygglatho 认为这是对他们彼此理解程度的考验。Chtholly 和 Willem 或许只把它看作另一种约定。无论世界如何变化,他们始终能够找到同一个位置。\n\n两位玩家分别是 Chtholly 和 Willem。评测程序扮演 Nygglatho,首先与 Chtholly 交互。Chtholly 完成操作后,评测程序再与 Willem 交互。Chtholly 和 Willem 可以提前约定所使用的策略,但不能直接向对方传递信息。\n\n在每个测试用例中,Nygglatho 准备一张由 $n \\times n$ 个格子组成的黑白图片,并选定一个目标格子 $x$。行和列的编号均为 $1$ 到 $n$。\n\n图片中包含 $w$ 个黑色格子。保证 $\gcd(n,w)=1$。\n\nNygglatho 首先将图片和目标格子 $x$ 展示给 Chtholly。Chtholly 必须选择两个格子并交换它们的颜色。允许选择同一个格子两次。如果选择的是同一个格子,或者两个格子的颜色相同,则图片不会发生变化。除此之外,她不能向 Willem 传递任何信息。\n\n交换颜色不会移动目标格子。\n\n随后,Nygglatho 会秘密地变换图片。她可以按照任意顺序执行以下操作任意次,也可以一次都不执行:\n\n1. 选择两个整数 $d_r$ 和 $d_c$($0\\le d_r,d_c \\lt n$),并循环移动图片。每个格子 $(r,c)$ 移动到 $\\left(\\left(r-1+d_r\\right)\\bmod n+1,\\left(c-1+d_c\\right)\\bmod n+1\\right)$;\n2. 将图片顺时针旋转 $90^\\circ$。一次旋转会将每个格子 $(r,c)$ 移动到 $(c,n+1-r)$;\n3. 将图片沿竖直轴翻转。这样的翻转会将每个格子 $(r,c)$ 移动到 $(r,n+1-c)$;\n4. 反转所有颜色。即将每个黑色格子变为白色格子,并将每个白色格子变为黑色格子。\n\n目标格子 $x$ 会与图片一起经历所有循环移动、旋转和翻转,并且方式完全相同。颜色反转不会移动目标格子。\n\n最后,Nygglatho 只将变换后的图片展示给 Willem。Willem 必须确定 $x$ 的最终位置。\n\n对于每个测试,程序将恰好运行两次。第一次运行时,程序必须扮演 Chtholly;第二次运行时,程序必须扮演 Willem。除了评测程序按照上述规则传递的信息外,两次运行之间不会保留任何信息。\n\n两次运行之间,测试用例的顺序可能发生变化。\n\n## 第一次运行\n\n在第一次运行中,你扮演 Chtholly。\n\n## 输入\n\n第一行包含字符串 first,表示这是第一次运行。\n\n在此行之后,剩余输入的格式如下。\n\n每次运行包含多个测试用例。第一行包含测试用例数量 $t$($1 \\le t \\le 10^4$)。接下来描述各个测试用例。\n\n每个测试用例的第一行包含一个整数 $n$($2 \\le n \\le 800$),表示图片的高和宽。\n\n接下来的 $n$ 行中,每行包含一个长度为 $n$ 的字符串。字符 $\\mathtt{\\#}$ 表示黑色格子,字符 $\\mathtt{.}$ 表示白色格子。\n\n下一行包含两个整数 $r_x$ 和 $c_x$($1 \\le r_x,c_x \\le n$),表示目标格子 $x$ 的行号和列号。\n\n令 $w$ 表示图片中的黑色格子数量。保证 $\\gcd(n,w)=1$。\n\n保证所有测试用例的 $n^2$ 之和不超过 $800^2$。\n\n## 输出\n\n对于每个测试用例,输出四个整数 $r_1$、$c_1$、$r_2$ 和 $c_2$($1 \\le r_1,c_1,r_2,c_2 \\le n$),表示 Chtholly 选择交换颜色的两个格子。允许选择同一个格子两次。\n\n## 第二次运行\n\n在第二次运行中,你扮演 Willem。\n\n## 输入\n\n第一行包含字符串 second,表示这是第二次运行。\n\n在此行之后,剩余输入的格式如下。\n\n每次运行包含多个测试用例。第一行包含测试用例数量 $t$($1 \\le t \\le 10^4$)。接下来描述各个测试用例。\n\n$t$ 的值与第一次运行相同,但测试用例的顺序可能不同。\n\n每个测试用例的第一行包含整数 $n$($2 \\le n \\le 800$)。\n\n接下来的 $n$ 行中,每行包含一个长度为 $n$ 的字符串,表示对应测试用例在 Chtholly 交换以及 Nygglatho 变换后的图片。同样,$\\mathtt{\\#}$ 表示黑色格子,$\\mathtt{.}$ 表示白色格子。\n\n保证所有测试用例的 $n^2$ 之和不超过 $800^2$。\n\n## 输出\n\n对于每个测试用例,输出两个整数 $r'_x$ 和 $c'_x$($1 \\le r'_x,c'_x \\le n$),表示目标格子经过所有变换后所在位置的行号和列号。\n\n本题禁止提交 Hack。\n\n## 说明\n\n第一个样例展示了两个测试用例的 Chtholly 运行过程。第二个样例展示了相同两个测试用例的 Willem 运行过程。Chtholly 运行过程中给出的输出只是一组可能的合法选择。\n\n在第一个测试用例中,Chtholly 交换了格子 $(1,1)$ 和 $(4,1)$。之后,两个黑色格子位于 $(2,2)$ 和 $(4,1)$。\n\n在这个例子中,Nygglatho 进行了以下变换:\n\n- 将图片向下循环移动一行,并向右循环移动两列;\n- 将图片顺时针旋转 $90^\\circ$ 一次;\n- 将图片沿竖直轴翻转。\n\n目标格子经过循环移动后从 $(3,4)$ 移动到 $(4,1)$,经过旋转后移动到 $(1,2)$,最后经过翻转移动到 $(1,4)$。两个黑色格子最终移动到 $(3,5)$ 和 $(4,3)$,这正好构成 Willem 运行时的图片。Willem 输出目标位置 $(1,4)$。\n\n在第二个测试用例中,Chtholly 可以选择同一个格子,此时图片不会发生变化。随后 Nygglatho 也可以什么都不做。"}AI (CI翻译)

样例

Input #1
first
2
5
#....
.#...
.....
.....
.....
3 4
5
.....
####.
.....
#####
.....
1 1
Output #1
1 1 4 1
1 1 1 1
InputCopy OutputCopy
Input #2
second
2
5
.....
####.
.....
#####
.....
5
.....
.....
....#
..#..
.....
Output #2
1 1
1 4
InputCopy OutputCopy
题目信息
题号
2256E
时间限制
2 s
内存限制
256 MB

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