P5635 [CSGRound1] The Best in the World

Background

After cbw, the best in the world, ruled the entire universe as chairman in the year 8102, he began to live a relaxed life and invited his friends to play games with him every day. Since cbw wanted to appear approachable, zhouwc, although a “juruo” (weak player), also got the chance to play with cbw.

Description

The game works as follows: Given two numbers $x$, $y$, and a modulus $p$. cbw has the number $x$, and zhouwc has the number $y$. Round 1: $x\leftarrow(x+y)\bmod p$. Round 2: $y\leftarrow(x+y)\bmod p$. Round 3: $x\leftarrow(x+y)\bmod p$. Round 4: $y\leftarrow(x+y)\bmod p$. And so on... If $x$ reaches $0$ first, then cbw wins. If $y$ reaches $0$ first, then zhouwc wins. If neither $x$ nor $y$ can reach $0$, then it is a draw. To protect his dignity as chairman, cbw wants to know the result of the game in advance, and he can also take the chance to “do something” behind the scenes. Therefore, he hopes you can tell him the result.

Input Format

There are multiple test cases. The first line contains $T$ and $p$, meaning there are $T$ test cases in total, and the modulus for all of them is $p$. The next $T$ lines each contain two numbers $x,y$.

Output Format

Output $T$ lines in total. $1$ means cbw wins, $2$ means zhouwc wins, and ```error``` means a draw.

Explanation/Hint

$1 \leq T \leq 200$. $1 \leq x,y,p \leq 10000$. Translated by ChatGPT 5