#P7509. [2017年杭电多校]Inverse of sum

[2017年杭电多校]Inverse of sum

Inverse of sum

Problem Description

There are nn nonnegative integers a1¡­na_{1¡­n} which are less than pp. HazelFan wants to know how many pairs i,j(1i<jn)i,j(1\leq i<j\leq n) are there, satisfying 1ai+aj1ai+1aj\frac{1}{a_i+a_j}\equiv\frac{1}{a_i}+\frac{1}{a_j} when we calculate module pp, which means the inverse element of their sum equals the sum of their inverse elements. Notice that zero element has no inverse element.

Input

The first line contains a positive integer T(1T5)T(1\leq T\leq5), denoting the number of test cases. For each test case: The first line contains two positive integers n,p(1n105,2p1018)n,p(1\leq n\leq10^5,2\leq p\leq10^{18}), and it is guaranteed that pp is a prime number. The second line contains nn nonnegative integers a1...n(0ai<p)a_{1...n}(0\leq a_i<p).

Output

For each test case: A single line contains a nonnegative integer, denoting the answer.

Sample Input

2

5 7

1 2 3 4 5

6 7

1 2 3 4 5 6

Sample Output

4

6

Source

2017 Multi-University Training Contest - Team 7

https://acm.hdu.edu.cn/showproblem.php?pid=6128