Euclidean Nim

For each pair of move sizes p and q and starting pile n, decide which player wins the take-or-add game, or that it draws.

Hard9Game theoryMathNumber theoryNo attempts yetTime limit2sMemory limit512 MB

Problem

Euclid and Pythagoras are the pseudonyms of two Byteotians who love mathematical puzzles. Lately they spend their evenings playing the following game. There is a stack of nn stones on the table, and the two friends move alternately. On his move, Euclid either takes any positive multiple of pp stones from the stack (allowed only when the stack holds at least pp stones) or adds exactly pp stones to the stack (allowed only when the stack holds fewer than pp stones). Pythagoras moves by the same rule with qq in place of pp: he either takes a multiple of qq stones or adds exactly qq stones. The player who empties the stack wins. Euclid moves first.

The friends wonder whether they have worked out this game completely. Help them: write a program that determines the result of the game when both players play optimally.

Input

The first line contains one integer tt (1t10001 \le t \le 1000), the number of test cases. Each of the next tt lines describes one test case with three integers pp, qq, nn (1p,q,n1091 \le p, q, n \le 10^9).

Output

Print exactly tt lines, the answers to the test cases in input order. The answer is the single letter E if Euclid can force a win no matter how Pythagoras plays, P if Pythagoras can force a win no matter how Euclid plays, or R (for remis, the Polish word for a draw) if the game goes on forever.

Hint

In the first test case of the sample (p=3p = 3, q=2q = 2, n=1n = 1) Euclid has to add three stones to the stack on his first move. Pythagoras then takes all 4 stones and wins.