P20542 [HackerEarth] Micro bought a new ball having an initial color K. He is also having N boxes of color, where i^th box contains color A[i]. He wants to paint his new ball. So he selects some boxes out of
普及-
题目描述

Micro bought a new ball having an initial color K. He is also having N boxes of color, where i^th box contains color A[i]. He wants to paint his new ball. So he selects some boxes out of the N boxes and paint the ball with the color in those boxes. If current color of ball is X and he paints it with a color Y the new color of the ball will be (X*Y)%M. The order in which he applies color on the ball does not matter. It is also possible that Micro does not choose any box in which case color of the ball does not change. Now Micro is interested in the expected value of the color on the ball. Expected value can be represented as $a rational number \frac{\textstyle P}{\textstyle Q}$ . If Q is not divisible by 10^9+7 there is a unique integer x (0 ≤ x < 10^9+7) where $P \equiv$ Qx % (10^9+7). He wants to know value of this integer x.

Input:
First line consists of an integer T denoting the number of test cases.
Second line consists of three space separated integers denoting N, K, and M.
Third line consists of N space separated integers denoting colors in the boxes.

Output:
Print the answer for each test case in a new line.

Constraints:
1 ≤ T ≤ 10
1 ≤ N, M ≤ 1000
1 ≤ K, A[i] ≤ 10^9

SAMPLE INPUT
1
2 1 10
1 2

SAMPLE OUTPUT
500000005

Explanation

Here Micro has 4 options to choose from:
i) Choose none : Color of ball will not change i.e. will remain 1
ii) Choose 1^st box: Color of ball will become (1 * 1)%10=1
iii) Choose 2^nd box: Color of ball will become (1 * 2)%10=2
iv) Choose both boxes: Color of ball will become (((1 * 1)%10) * 2)%10 = 2

So expected value $= \frac{\textstyle (2 * 1 + 2 * 2) }{\textstyle 4} = \frac{\textstyle 6}{\textstyle 4}$
And finally we have 6 = (4 * 500000005)%(10^9+7). So x=500000005

输入格式

见题面

输出格式

见题面

样例输入
3 84 3164 387 916 794 336 387 493 650 422 363 28 691 60 764 927 541 427 173 737 212 369 568 430 783 531 863 124 68 136 930 803 23 59 70 168 394 457 12 43 230 374 422 920 785 538 199 325 316 371 414 527 92 981 957 874 863 171 997 282 306 926 85 328 337 506 847 730 314 858 125 896 583 546 815 368 435 365 44 751 88 809 277 179 789 585 404 52 2654 255 933 61 677 369 740 13 227 587 95 540 796 571 435 379 468 602 98 903 318 493 653 757 302 281 287 442 866 690 445 620 441 730 32 118 98 772 482 676 710 928 568 857 498 354 587 966 307 684 220 625 529 872 33 9833 330 20 271 369 709 716 341 150 797 724 619 246 847 452 922 556 380 489 765 229 842 351 194 501 35 765 125 915 988 857 744 492 228 366
样例输出
363965991 557975043 151084441 782149777 631538169