Little Desprado2 doesn't think it is interesting enough since everybody knows it. Now, he wants demonstrate some properties of the GCD by generating some infinite sequences. He has two positive integers $$$P$$$ and $$$Q$$$, and $$$Q|P$$$ is satisfied. Here $$$a|b$$$ means that $$$a$$$ is a factor of $$$b$$$, that is, $$$b \bmod a = 0$$$. And he has $$$k$$$ candidate pairs of positive numbers $$$\{(a_1,b_1),(a_2,b_2),...,(a_k,b_k)\}$$$ to generate $$$k$$$ infinite sequence, where the $$$i$$$-th sequence $$$\{x_{i,0},\ x_{i,1},\ x_{i,2},\ ...\}$$$ is generated by the following rules:
He thinks that an infinite sequence $$$\{x_0,\ x_1,\ x_2,\ ...\}$$$ is demonstrational, if and only if there exists two integers $$$u$$$ and $$$v$$$ ($$$0\le v \lt u$$$) such that $$$\gcd(x_u-x_v, P) = Q$$$. Here $$$\gcd(a,b)$$$ denotes the greatest common divisor of $$$a$$$ and $$$b$$$.
For each infinite sequences, Little Desprado2 wants you to tell him whether it is demonstrational.
The first line contains three integers $$$P, Q, k$$$ ($$$1\le P\le 2^{32}-1$$$, $$$1\le Q\le 2^{20}$$$, $$$1\le k\le 200$$$). It's guaranteed that $$$Q|P$$$ is satisfied.
Then follows $$$k$$$ lines. The $$$i$$$-th line contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1\le a_i,\ b_i\le 2^{64}-1$$$), denoting the $$$i$$$-th pair of numbers.
Print a $$$0/1$$$ string of length $$$k$$$. The $$$i$$$-th character is $$$1$$$ if the $$$i$$$-th infinite sequence is demonstrational, $$$0$$$ otherwise.
15 5 5 1 1 1 2 2 4 4 8 8 16
11010
998244352 1048576 3 2022 924 12345678 1234567 23333333 6666666
001
In the first example,
| Название |
|---|


