Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems. 

The boy has found an online judge with tasks divided by topics they cover. He has picked $p^{k_i}$ problems from $i$-th category ($p$ is his favorite number). He wants to solve them in two weeks (the patience condition is too hard for Johnny, so for simplicity, he looks only at easy tasks, which can be solved in such a period). Now our future grandmaster has to decide which topics to cover first and which the second week. Help him assign topics in such a way, that workload is balanced.

Formally, given $n$ numbers $p^{k_i}$, the boy wants to divide them into two disjoint sets, minimizing the absolute difference between sums of numbers in each set. Find the minimal absolute difference. Output the result modulo $10^{9}+7$.


-----Input-----

Input consists of multiple test cases. The first line contains one integer $t$ $(1 \leq t \leq 10^5)$ — the number of test cases. Each test case is described as follows:

The first line contains two integers $n$ and $p$ $(1 \leq n, p \leq 10^6)$. The second line contains $n$ integers $k_i$ $(0 \leq k_i \leq 10^6)$.

The sum of $n$ over all test cases doesn't exceed $10^6$.


-----Output-----

Output one integer — the reminder of division the answer by $1\,000\,000\,007$.


-----Example-----
Input
4
5 2
2 3 4 4 3
3 1
2 10 1000
4 5
0 1 1 100
1 8
89

Output
4
1
146981438
747093407



-----Note-----

You have to minimize the difference, not it's remainder. For example, if the minimum difference is equal to $2$, but there is also a distribution where the difference is $10^9 + 8$, then the answer is $2$, not $1$.

In the first test case of the example, there're the following numbers: $4$, $8$, $16$, $16$, and $8$. We can divide them into such two sets: ${4, 8, 16}$ and ${8, 16}$. Then the difference between the sums of numbers in sets would be $4$.

Difficulty: competition

Starter code:

Solutions:
import sys
input = sys.stdin.readline

MOD = 10 ** 9 + 7

t = int(input())
for _ in range(t):
    n, p = list(map(int, input().split()))
    l = list(map(int, input().split()))
    if p == 1:
        print(n % 2)
    else:
        l.sort(reverse = True)
        curr = l[0]
        out = 0
        real = True

        for v in l:
            if v < curr:
                diff = curr - v
                if 10 ** (7/diff) < p and out > 0:
                    real = False
                out *= pow(p, diff, MOD)
                if out > 10 ** 7:
                    real = False
                out %= MOD

                curr = v
            if out > 0 or not real:
                out -= 1
            else:
                out += 1
            out %= MOD

        out *= pow(p, curr, MOD)
        print(out % MOD)


import sys
readline = sys.stdin.readline

T = int(readline())
Ans = [None]*T
MOD = 10**9+7
mod = 10**9+9
for qu in range(T):
    N, P = map(int, readline().split())
    A = list(map(int, readline().split()))
    if P == 1:
        if N&1:
            Ans[qu] = 1
        else:
            Ans[qu] = 0
        continue
    if N == 1:
        Ans[qu] = pow(P, A[0], MOD)
        continue
    A.sort(reverse = True)
    cans = 0
    carry = 0
    res = 0
    ra = 0
    for a in A:
        if carry == 0:
            carry = pow(P, a, mod)
            cans = pow(P, a, MOD)
            continue
        res = (res + pow(P, a, mod))%mod 
        ra = (ra + pow(P, a, MOD))%MOD
        
        if res == carry and ra == cans:
            carry = 0
            cans = 0
            ra = 0
            res = 0
    Ans[qu] = (cans-ra)%MOD
        
        
print('\n'.join(map(str, Ans)))

import sys
input = sys.stdin.readline
mod=1000000007

t=int(input())
for tests in range(t):
    n,p=list(map(int,input().split()))
    K=sorted(map(int,input().split()),reverse=True)

    if p==1:
        if n%2==0:
            print(0)
        else:
            print(1)
        continue

    ANS=[0,0]
    flag=0

    for i in range(n):
        k=K[i]
        
        if ANS[0]==0:
            ANS=[1,k]
            
        elif ANS[1]==k:
            ANS[0]-=1

        else:
            while ANS[1]>k:
                ANS[0]*=p
                ANS[1]-=1

                if ANS[0]>10**7:
                    flag=1
                    lastind=i
                    break

            if flag==1:
                A=ANS[0]*pow(p,ANS[1],mod)%mod
                #print(A,ANS)

                for j in range(lastind,n):
                    A=(A-pow(p,K[j],mod))%mod
                print(A)
                break
            else:
                ANS[0]-=1

    if flag==0:
        print(ANS[0]*pow(p,ANS[1],mod)%mod)
                    
                    
    

    

    


import sys
input = lambda: sys.stdin.readline().rstrip()


T = int(input())
P = 10 ** 9 + 7
for _ in range(T):
    N, b = list(map(int, input().split()))
    A = sorted([int(a) for a in input().split()])
    if b == 1:
        print(N % 2)
        continue
    a = A.pop()
    pre = a
    s = 1
    ans = pow(b, a, P)
    while A:
        a = A.pop()
        s *= b ** min(pre - a, 30)
        if s >= len(A) + 5:
            ans -= pow(b, a, P)
            if ans < 0: ans += P
            while A:
                a = A.pop()
                ans -= pow(b, a, P)
                if ans < 0: ans += P
            print(ans)
            break
        
        if s:
            s -= 1
            ans -= pow(b, a, P)
            if ans < 0: ans += P
            pre = a
        else:
            s = 1
            ans = -ans
            if ans < 0: ans += P
            ans += pow(b, a, P)
            if ans >= P: ans -= P
            pre = a
    else:
        print(ans)