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 ≤ t ≤ 10^5) — the number of test cases. Each test case is described as follows:

The first line contains two integers n and p (1 ≤ n, p ≤ 10^6). The second line contains n integers k_i (0 ≤ k_i ≤ 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.
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18 + 1e17;
const long long mod = 1e9 + 7;
long long modInverse(long long a, long long m) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
long long powm(long long a, long long b) {
  a = a % mod;
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return (res % mod);
}
const long long N = 2e6 + 5;
long long arr[N];
void solve(long long t) {
  long long n, p;
  cin >> n >> p;
  set<long long> s;
  for (long long i = 0; i < n; i++) {
    long long aa;
    cin >> aa;
    if (p != 1) {
      arr[aa]++;
      s.insert(aa);
    }
  }
  if (p == 1 && n % 2) {
    cout << 1 << '\n';
    return;
  }
  if (p == 1) {
    cout << 0 << '\n';
    return;
  }
  long long kal = log2(n + 100);
  vector<long long> v;
  while (s.size()) {
    v.push_back(*s.begin());
    s.erase(s.begin());
  }
  reverse(v.begin(), v.end());
  bool bo = false;
  long long val = -1;
  for (long long i = 0; i < v.size(); i++) {
    long long x = v[i];
    if (arr[x] % 2 == 0 && bo == false) {
      arr[x] = 0;
      continue;
    } else if (arr[x] % 2 && bo == false) {
      arr[x] = 1;
      bo = true;
      val = x;
    } else {
      while (arr[x] >= p) {
        long long c = x;
        while (c < val && arr[c] >= p) {
          arr[c] -= p;
          arr[c + 1] += 1;
          c++;
        }
        if (c == val) {
          arr[val] = 0;
          if (arr[x] % 2 == 0) {
            arr[x] = 0;
            bo = false;
          } else if (arr[x] % 2 == 1) {
            val = x;
            arr[x] = 1;
            bo = true;
          }
        } else
          continue;
      }
    }
  }
  if (bo == false) {
    cout << 0 << '\n';
    return;
  }
  long long ans = 0, ans2 = 0;
  for (long long i = 0; i < v.size(); i++) {
    long long x = v[i];
    if (arr[x] == 1 && bo) {
      ans += powm(p, x);
      arr[x] = 0;
      bo = false;
    } else if (!bo) {
      for (long long j = x; j <= x + kal; j++) {
        if (arr[j] > 0) {
          ans2 += (arr[j] * powm(p, j)) % mod;
          arr[j] = 0;
        }
      }
    }
  }
  cout << (ans - (ans2 % mod) + mod) % mod << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(arr, 0, sizeof(arr));
  long long t = 1;
  cin >> t;
  for (long long i = 1; i <= t; i++) {
    solve(i);
  }
}
