{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eAs a cold-blooded, hot-blooded, and iron-blooded vampire, Shinobu loves traveling around.\u003cbr\u003e\u003cbr\u003eThere are $P$ countries in total, numbered $0,1,\\dots ,P-1$.(It is guaranteed that $P$ is a prime number)\u003cbr\u003e\u003cbr\u003eIt 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. \u003cbr\u003e\u003cbr\u003eIn 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$.\u003cbr\u003e\u003cbr\u003eFor example, if $P \u003d 233,\\ a \u003d 2$, a plan\u0027s starting country is $1$ and travel days is $2$, then Shinobu will visit the city $\\{ 1,2,4 \\}$ according to this plan.\u003cbr\u003e\u003cbr\u003ePlayf 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$.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains one integer $T$ $($$1\\leq T\\leq 5$ $)$ --- the number of test cases. Then $T$ test cases follow.\u003cbr\u003e\u003cbr\u003eFor each testcase, the first line contains four integers $P,\\ a,\\ n,\\ q(2\\le a\u0026lt; P \\le 1000000007, 1\\le n \\le 1000, 1\\le q \\le 1000 )$ --- the number of countries, the value of $a$, the number of Shinobu\u0027s travel plans and the number of playf\u0027s questions.\u003cbr\u003e\u003cbr\u003eEach of the next $n$ lines contains two integers $s_i,\\ d_i(0\\le s_i\u0026lt; P, 1\\le d_i \\le 200000 )$ --- the starting country and the travel days.\u003cbr\u003e\u003cbr\u003eEach of the next $q$ lines contains one integer $x_i(0\\le x_i\u0026lt; P)$ --- playf\u0027s questions.\u003cbr\u003e\u003cbr\u003eIt is guaranteed that $P$ is a prime number."}},{"title":"Output","value":{"format":"HTML","content":"For each testcase, print $q$ lines, the $i$-th line contains one integer --- the answer to the $i$-th question."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n3 2 1 1\r\n1 1\r\n2\r\n5 4 3 2\r\n1 4\r\n4 3\r\n2 100000\r\n4\r\n2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n2\r\n1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}