P6814 [PA 2009] Circular Game

Description

There is a circular board of size $m$, with $a$ white pieces and $b$ black pieces on it. White moves first. In one move, a piece may move to a position such that there are no pieces on any position in between. For example, in the figure below, the piece at position $8$ can move to any of positions $1, 7, 9$. ![](https://cdn.luogu.com.cn/upload/image_hosting/u9d5ifjt.png?x-oss-process=image/resize,m_lfit,h_300,w_300)

Input Format

The first line contains an integer $t$, the number of test cases. For each test case, the first line contains three integers $m$, $a$, and $b$, representing the board length, the number of white pieces, and the number of black pieces. The second line of each test case contains a strictly increasing sequence of integers, representing the positions of the white pieces. The third line of each test case contains a strictly increasing sequence of integers, representing the positions of the black pieces.

Output Format

For each test case, output a single character: $B$, $C$, or $R$. Output $B$ if White wins, output $C$ if Black wins, and output $R$ if the game never ends.

Explanation/Hint

Constraints: $1 \leq m \leq 10^9$, $1 \leq \sum a + b \leq 10^6$. Translated by ChatGPT 5