#P8700. [蓝桥杯 2019 国 B] 解谜游戏

[蓝桥杯 2019 国 B] 解谜游戏

Background

Problem Description

Xiaoming is playing a puzzle game. The puzzle consists of 2424 plastic sticks: 44 yellow sticks, 88 red sticks, and 1212 green sticks (later we use Y for yellow, R for red, and G for green). Initially, these sticks are arranged into three rings as shown in the picture above: the outer ring has 1212 sticks, the middle ring has 88 sticks, and the inner ring has 44 sticks.

Xiaoming can perform three kinds of operations:

  1. Rotate all three rings clockwise by one unit. For example, suppose the outer ring from the 00 o’clock position clockwise is YRYGRYGRGGGG, the middle ring is RGRGGRRY, and the inner ring is GGGR. After one clockwise rotation, the outer, middle, and inner rings become GYRYGRYGRGGG, YRGRGGRR, and RGGG, respectively.
  2. Rotate all three rings counterclockwise by one unit. For example, suppose the outer ring from the 00 o’clock position clockwise is YRYGRYGRGGGG, the middle ring is RGRGGRRY, and the inner ring is GGGR. After one counterclockwise rotation, the outer, middle, and inner rings become RYGRYGRGGGGY, GRGGRRYR, and GGRG, respectively.
  3. Perform a cyclic shift of the sticks at the 00 o’clock position of the three rings. Specifically: the outer-ring stick at 00 o’clock moves to the inner ring at 00 o’clock, the inner-ring stick at 00 o’clock moves to the middle ring at 00 o’clock, and the middle-ring stick at 00 o’clock moves to the outer ring at 00 o’clock. For example, suppose the outer ring from the 00 o’clock position clockwise is YRYGRYGRGGGG, the middle ring is RGRGGRRY, and the inner ring is GGGR. After one cyclic shift, the outer, middle, and inner rings become RRYGRYGRGGGG, GGRGGRRY, and YGGR, respectively.

Xiaoming’s goal is to move all green sticks to the outer ring, all red sticks to the middle ring, and all yellow sticks to the inner ring. Given the initial state, determine whether Xiaoming can achieve the goal.

Input Format

The first line contains an integer TT, the number of test cases. (1T100)(1 \le T \le 100).

Each test case contains 33 lines:

The first line contains 1212 uppercase letters, representing the colors of the outer ring clockwise starting from the 00 o’clock position.

The second line contains 88 uppercase letters, representing the colors of the middle ring clockwise starting from the 00 o’clock position.

The third line contains 44 uppercase letters, representing the colors of the inner ring clockwise starting from the 00 o’clock position.

Output Format

For each test case, output one line YES or NO, indicating whether Xiaoming can achieve the goal.

2
GYGGGGGGGGGG
RGRRRRRR
YRYY
YGGGRRRRGGGY
YGGGRRRR
YGGG

YES
NO

Hint

Lanqiao Cup 2019 National Contest B Group, Problem H.

Translated by ChatGPT 5