You are given an array containing ‘N’ integers. You need to find the number of subsequences of length 3 which are in Geometric progression with common ratio ‘R’.
A geometric progression (GP), also called a geometric sequence, is a sequence of numbers that differ from each other by a common ratio. For example, the sequence 2,4,8,16,… is a geometric sequence with common ratio 2.
Note:
As the answer can be very large you need to return the answer in mod 10^9+7.
Input Format:
The first line of the input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains two space-separated positive integers ‘N’ and ‘R’ denoting the number of the elements present in the array and the common ratio of GP.
The second line of each test case contains ‘N’ space-separated integers denoting the elements of the array.
Output Format:
The only line of output of each test case should contain the number of the subsequence of length 3 having a common ratio ‘R’.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 50
3 <= N <= 10^4
1 <= R <= 10^4
1 <= A[i] <= 10^9
Time Limit: 1 sec