#P1951G. Clacking Balls

    ID: 9251 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 10 Uploaded By: Tags>combinatoricsmathprobabilities*3100

Clacking Balls

No submission language available for this problem.

Description

There are mm baskets placed along a circle, numbered from 11 to mm in clockwise order (basket mm is next to basket 11). Furthermore, there are nn balls, where ball ii is initially placed in basket aia_i, and no basket contains more than one ball.

Alice is allowed to perform the following operation, which always takes exactly one second whether you move/throw a ball or not:

  • Alice chooses an integer ii between 11 and nn uniformly at random.
  • If ball ii was thrown away before, do nothing.
  • Otherwise, ball ii is moved from the basket currently containing it to the next basket (in clockwise order). If the target basket currently contains another ball jj, throw ball jj away.

She repeats this operation until there is exactly one ball left. Calculate the expected time needed (in seconds) for Alice to end the process.

It can be proven that the answer can be represented as a rational number pq\frac{p}{q} with coprime pp and qq. You need to output pq1mod109+7p \cdot q^{-1} \bmod 10^9 + 7. It can be proven that 109+7q10^9 + 7 \nmid q.

Each test contains multiple test cases. The first line contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1n3105,nm1091 \le n \le 3 \cdot 10^5, n \le m \le 10^9) — the number of balls and the number of baskets.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1aim1 \le a_i \le m, aia_i's are pairwise distinct) — the initial position of each ball.

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5.

For each test case, print one integer: the expected amount of time (in seconds) Alice needs to end the process, modulo 109+710^9 + 7.

Input

Each test contains multiple test cases. The first line contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1n3105,nm1091 \le n \le 3 \cdot 10^5, n \le m \le 10^9) — the number of balls and the number of baskets.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1aim1 \le a_i \le m, aia_i's are pairwise distinct) — the initial position of each ball.

It is guaranteed that the sum of nn over all test cases does not exceed 31053 \cdot 10^5.

Output

For each test case, print one integer: the expected amount of time (in seconds) Alice needs to end the process, modulo 109+710^9 + 7.

Sample Input 1

5
3 10
5 1 4
2 15
15 1
6 6
1 2 3 4 5 6
6 9
6 5 4 3 2 1
1 100
69

Sample Output 1

600000042
14
35
333333409
0

Note

In the first test case, Alice could have proceeded as follows (we define ai=1a_i = -1 if ball ii has been thrown out):

  • Initially, a=[5,1,4]a = [5, 1, 4].
  • Alice chooses i=2i = 2 with probability 13\frac{1}{3}, and ball 22 is moved to basket 22. After this, a=[5,2,4]a = [5, 2, 4].
  • Alice chooses i=2i = 2 with probability 13\frac{1}{3}, and ball 22 is moved to basket 33. After this, a=[5,3,4]a = [5, 3, 4].
  • Alice chooses i=2i = 2 with probability 13\frac{1}{3}, and ball 22 is moved to basket 44. As basket 44 previously contains ball 33, this ball is thrown out. After this, a=[5,4,1]a = [5, 4, -1].
  • Alice chooses i=3i = 3 with probability 13\frac{1}{3}. Ball 33 has already been thrown out, so nothing happens. After this, a=[5,4,1]a = [5, 4, -1].
  • Alice chooses i=2i = 2 with probability 13\frac{1}{3}, and ball 22 is moved to basket 55, which throws out ball 11. After this, a=[1,5,1]a = [-1, 5, -1], and the process ends.
The answer for this test case is 1895\frac{189}{5}.

The answer for the second test case is 1414 (note that these two balls are next to each other).

The answer for the third test case is 3535.

The answer for the fourth test case is 2203\frac{220}{3}.

In the fifth test case, as there is only one ball initially, the answer is 00.