P8700 [Lanqiao Cup 2019 National Contest B] Puzzle Game
Background

Description
Xiaoming is playing a puzzle game. The puzzle consists of $24$ plastic sticks: $4$ yellow sticks, $8$ red sticks, and $12$ 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 $12$ sticks, the middle ring has $8$ sticks, and the inner ring has $4$ 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 $0$ 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 $0$ 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 $0$ o’clock position of the three rings. Specifically: the outer-ring stick at $0$ o’clock moves to the inner ring at $0$ o’clock, the inner-ring stick at $0$ o’clock moves to the middle ring at $0$ o’clock, and the middle-ring stick at $0$ o’clock moves to the outer ring at $0$ o’clock. For example, suppose the outer ring from the $0$ 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 $T$, the number of test cases. $(1 \le T \le 100)$.
Each test case contains $3$ lines:
The first line contains $12$ uppercase letters, representing the colors of the outer ring clockwise starting from the $0$ o’clock position.
The second line contains $8$ uppercase letters, representing the colors of the middle ring clockwise starting from the $0$ o’clock position.
The third line contains $4$ uppercase letters, representing the colors of the inner ring clockwise starting from the $0$ o’clock position.
Output Format
For each test case, output one line `YES` or `NO`, indicating whether Xiaoming can achieve the goal.
Explanation/Hint
Lanqiao Cup 2019 National Contest B Group, Problem H.
Translated by ChatGPT 5