#P9971. [THUPC 2024 初赛] 三步棋

[THUPC 2024 初赛] 三步棋

Background

The days are short and the nights are long as the winter solstice approaches. The river is cold and pitch-black, yet pink clouds rise in the east. Outside the window, sleepy seagulls and egrets form lines; inside the room, fragrance fills the air as morning cooking begins.

Study by day and work by dusk make one drowsy. In the quiet of night, one reads until the lamp burns out and then sleeps. Please help share the heavy work, so we can dance freely and have a smooth birthday.

Problem Description

There is an unwritten rule in K's home. If there are only K and H at home, they decide who cooks by playing a game called “Three-Step Gomoku”. Its rules are somewhat similar to Gomoku. As is well known, Gomoku is a game where the first player to connect five of their own pieces wins. Similarly, in Three-Step Gomoku, the two players take turns placing pieces on a grid board, and the winner is determined by whether a specified pattern is formed. Different from Gomoku:

  1. Three-Step Gomoku does not distinguish between the two players' pieces. That is, you may assume both players use pieces of the same color.

  2. When judging, the specified pattern cannot be rotated.

  3. If the specified pattern is formed and the total number of pieces on the board is exactly a multiple of 33, then the player who formed the pattern wins; otherwise, that player is judged to lose (i.e., the opponent wins).

For example, if the specified pattern is

.o
oo

and the current board is

o..o.
o.o..
oo...
o.o..
o..o.

then we consider that the given polyline-shaped pattern has not been formed, where o represents a piece and . represents an empty cell. But if a piece is placed next at row 22, column 22, then the given pattern is formed. The corresponding pieces are marked with @:

o..o.
o@o..
@@...
o.o..
o..o.

At this time, there are exactly 1111 pieces on the board, and 1111 is not a multiple of 33, so the player who placed this piece, i.e. the first player, loses this round.

In K's home, to save time, they usually play Three-Step Gomoku on an initially empty 5×55\times 5 board. Also, each time they randomly choose one 4-connected pattern consisting of at most 44 pieces. Clearly, there is no draw in Three-Step Gomoku, so K and H agree that the loser is responsible for cooking. K wants to know, if both she and H are smart enough, whether the Three-Step Gomoku game with the chosen pattern is a first-player win; because if she can win more easily, she will secretly go easy on her younger sister.

Input Format

The input file contains multiple test cases.

The first line contains a positive integer TT, denoting the number of test cases. It is guaranteed that 1T2001\le T\le 200.

For each test case, the input consists of 55 lines. Each line contains a string of length 55 consisting only of . and o, representing the specified pattern. It is guaranteed that in each test case, o appears at least once, and all o form a 4-connected block of size at most 44.

Output Format

For each test case, output one line. If the input pattern is a first-player win, output Far; otherwise output Away.

3
.....
oo...
.....
.....
.....
.o...
.o...
.....
.....
.....
.....
.....
.....
.ooo.
.....

Far
Far
Away

Hint

Explanation of Sample #1

This sample contains three test cases.

In the first test case, the input pattern is oo in row 11, column 22. Obviously, no matter where the first player places their piece on the board, the second player has only two strategies:

  • Connect with the first player's piece to form oo. At this time there are only 22 pieces on the board, so the second player immediately loses.

  • Do not connect with the first player's piece to form oo. But then it is the first player's turn, and the first player can form oo anywhere. At this time there are exactly 33 pieces on the board, so the first player wins.

No matter which strategy is used, the second player cannot win. Therefore, for oo the game is a first-player win.

In the second test case, the input pattern is a 22-row 11-column pattern. By the same reasoning as oo, it is also a first-player win.

In the third test case, the input pattern is ooo in a 11-row 33-column shape. It can be proven that the first player must lose.

Subtasks

It is guaranteed that 1T2001\le T\le 200. For each test case, it is guaranteed that in the 5×55\times 5 character matrix consisting of . and o, there is at least one o, and all o form a 4-connected block of size at most 44.

Problem License

From the THUPC2024 Preliminary (Tsinghua University Student Programming Contest and Collegiate Invitational, 2024) preliminary round.

The following “this repository” refers to the THUPC2024 Preliminary official repository (https://github.com/ckw20/thupc2024_pre_public).

  1. Any organization or individual may use or repost the problems in this repository for free.

  2. Any organization or individual, when using the problems in this repository, should do so without charge and publicly. It is strictly forbidden to use these problems for profit or to add special access restrictions to them.

  3. If possible, when using the problems in this repository, also provide ways to obtain resources such as testdata, reference solutions, and editorials. Otherwise, please attach the GitHub address of this repository.

Translated by ChatGPT 5