You are given an array A consisting of N non-negative integers. You are also given 2 integers p(a prime number) and k. You are required to count number of pairs (i,j) where, 1≤i<j≤N and satisying:
(A2i+A2j+Ai∗Aj) mod p=k
where a mod p=b means that b is the remainder when a is divided by p. In particular, 0≤b<p.
You are given T test cases.
Input format
Output format
For each test case, print the number of pairs satisfying the equation in a separate line.
Constraints
1≤T≤10001≤N≤5×1051≤p≤109p is prime0≤k<p0≤Ai≤109Sum of N over all test cases does not exceed 106
In the first sample, N=4,k=1,p=2,A=[3,2,1,0]. Caculations for each pair (i,j) are shown below:
In the second sample, N=8,k=0,p=3,A=[9,2,1,8,4,5,9,10]. Valid pairs (i,j) are: (1,7),(2,4),(2,6),(3,5),(3,8),(4,6),(5,8).