As a cold-blooded, hot-blooded, and iron-blooded vampire, Shinobu loves traveling around.
There are $P$ countries in total, numbered $0,1,\dots ,P-1$.(It is guaranteed that $P$ is a prime number)
It is known that when Shinobu is in the country numbered $i$, the next country she visits must be the country numbered $(i\cdot a) \mod P$ ($a$ is a constant parameter), and it takes Shinobu $1$ day to go from one country to another.
In order to travel smoothly, Shinobu has customized $n$ travel plans, and the $i$-th travel plan is represented by the starting country $s_i$ and the travel days $d_i$.
For example, if $P = 233,\ a = 2$, a plan's starting country is $1$ and travel days is $2$, then Shinobu will visit the city $\{ 1,2,4 \}$ according to this plan.
Playf knows these travel plans and the value of parameter $a$, now he wants to ask you $q$ questions. The $i$-th question asks how many travel plans will make shinobu visit the country $x_i$.