#CF2236F2. 萨兰斯克选举(困难版) / F2. Elections in Saransk (hard version)

萨兰斯克选举(困难版) / F2. Elections in Saransk (hard version)

F2. Elections in Saransk (hard version)

Source: Codeforces 2236F2
Contest: Codeforces Round 1103 (Div. 3)
Time limit: 3 seconds
Memory limit: 512 megabytes

Statement

This is the hard version of the problem. The only difference is that 1x51051 \le x \le 5 \cdot 10^5.

On the way home after buying his favorite soda "Zola Cero", Egor saw that elections for the position of "Best Number" are taking place in Saransk.

There are nn people at the polling station. Each person brought a number aia_i. When the ii-th person enters the voting booth, they choose a candidate that is a divisor of the number aia_i. Let the chosen candidate be pip_i.

After everyone has voted, we get an array of votes [p1,p2,,pn][p_1, p_2, \ldots, p_n].

Egor really likes the number xx and considers the voting ideal if xlcm(p1,p2,,pn)x \cdot {lcm}(p_1, p_2, \ldots, p_n)^{\text{∗}} = p1p2pnp_1 \cdot p_2 \cdot \ldots \cdot p_n. Help him find the number of different^{\text{†}} arrays pp modulo 109+710^9 + 7 that are ideal.

^{\text{∗}}lcmlcmleast common multiple.

^{\text{†}}Two arrays of votes are considered different if there exists an index ii where the two arrays have different elements.

Input

The first line contains a single integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

Then tt test cases follow.

The first line of each test case contains two integers nn and xx (1n1051 \leq n \leq 10^5, 1x51051 \leq x \leq 5 \cdot 10^5) — the number of voters at the polling station and Egor's favorite number.

The second line of each test case contains nn integers: a1,a2,,ana_1, a_2, \dots, a_n (1ai51051 \leq a_i \leq 5 \cdot 10^5) — the numbers brought by the voters.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, output the number of ways modulo 109+710^9 + 7 to vote so that the resulting array of votes satisfies the condition.

Examples

5
2 2
2 4
1 5
5
7 4
2 4 8 13 111 6 7
3 1000
1 2 3
3 3
4 8 10
2
0
360
0
0