#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 .
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 people at the polling station. Each person brought a number . When the -th person enters the voting booth, they choose a candidate that is a divisor of the number . Let the chosen candidate be .
After everyone has voted, we get an array of votes .
Egor really likes the number and considers the voting ideal if = . Help him find the number of different arrays modulo that are ideal.
Two arrays of votes are considered different if there exists an index where the two arrays have different elements.
Input
The first line contains a single integer () — the number of test cases.
Then test cases follow.
The first line of each test case contains two integers and (, ) — the number of voters at the polling station and Egor's favorite number.
The second line of each test case contains integers: () — the numbers brought by the voters.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the number of ways modulo 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