#P5635. 【CSGRound1】天下第一

【CSGRound1】天下第一

Description

The game works as follows:

Given two numbers xx, yy, and a modulus pp.

cbw has the number xx, and zhouwc has the number yy.

Round 1: x(x+y)modpx\leftarrow(x+y)\bmod p.

Round 2: y(x+y)modpy\leftarrow(x+y)\bmod p.

Round 3: x(x+y)modpx\leftarrow(x+y)\bmod p.

Round 4: y(x+y)modpy\leftarrow(x+y)\bmod p.

And so on...

If xx reaches 00 first, then cbw wins. If yy reaches 00 first, then zhouwc wins. If neither xx nor yy can reach 00, 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 TT and pp, meaning there are TT test cases in total, and the modulus for all of them is pp.

The next TT lines each contain two numbers x,yx,y.

Output Format

Output TT lines in total.

11 means cbw wins, 22 means zhouwc wins, and error means a draw.

1 10
1 3

error
1 10
4 5

1

Hint

1T2001 \leq T \leq 200.

1x,y,p100001 \leq x,y,p \leq 10000.

Translated by ChatGPT 5