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 double PI = acos(-1.0);
const int INF = 1e9 * 2;
const long long LINF = (long long)1e18;
const double EPS = 1e-7;
const int mod = 998244353;
const int MOD = 1e9 + 7;
struct segment_Treee {
  struct node {
    long long set;
    long long min;
  };
  vector<node> t;
  long long no_operation = LLONG_MIN;
  long long op_mod(long long a, long long b) {
    if (b == no_operation) return a;
    return b;
  }
  long long op_mn(long long a, long long b) { return min(a, b); }
  void propagate(int v, int tl, int tr) {
    if (t[v].set == no_operation || tr - tl == 1) return;
    int tm = (tl + tr) / 2;
    t[v * 2 + 1].set = op_mod(t[v * 2 + 1].set, t[v].set);
    t[v * 2 + 1].min = op_mod(t[v * 2 + 1].min, t[v].set);
    t[v * 2 + 2].set = op_mod(t[v * 2 + 2].set, t[v].set);
    t[v * 2 + 2].min = op_mod(t[v * 2 + 2].min, t[v].set);
    t[v].set = no_operation;
  }
  int sz = 1;
  long long neutral = LLONG_MAX;
  void build(int n) {
    while (sz < n) sz *= 2;
    t.resize(2 * sz - 1);
  }
  void update(int v, int tl, int tr, int l, int r, int val) {
    propagate(v, tl, tr);
    if (l >= tr || r <= tl) return;
    if (l <= tl && r >= tr) {
      t[v].set = op_mod(t[v].set, val);
      t[v].min = op_mod(t[v].min, val);
      return;
    }
    int tm = (tl + tr) / 2;
    update(v * 2 + 1, tl, tm, l, r, val);
    update(v * 2 + 2, tm, tr, l, r, val);
    t[v].min = op_mn(t[v * 2 + 1].min, t[v * 2 + 2].min);
  }
  void update(int l, int r, int val) { update(0, 0, sz, l, r, val); }
  long long get(int v, int tl, int tr, int l, int r) {
    propagate(v, tl, tr);
    if (l >= tr || r <= tl) return neutral;
    if (tl >= l && tr <= r) return t[v].min;
    int tm = (tl + tr) / 2;
    long long mn1 = get(v * 2 + 1, tl, tm, l, r);
    long long mn2 = get(v * 2 + 2, tm, tr, l, r);
    return op_mn(mn1, mn2);
  }
  long long get(int l, int r) { return get(0, 0, sz, l, r); }
} T;
const int nax = 1e6 + 10;
void mul(int &a, int b) { a = a * 1ll * b % MOD; }
int cnt[nax];
void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += MOD;
}
int dod(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}
int vid(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}
void add(int &a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) mul(res, a);
    mul(a, a);
    n >>= 1;
  }
  return res;
}
void sub(int &a, long long b) {
  a = 1ll * a - b;
  if (a < 0) a += MOD;
}
int func(int count, int p, int num) {
  int ans = 1;
  for (int i = (0); i < (num); i++) {
    if (ans * 1ll * p > INF) return -1;
    ans *= p;
  }
  if (ans * 1ll * count > INF) return -1;
  return count * ans;
}
int mul_1(int a, int b) { return a * 1ll * b % MOD; }
void solve() {
  int n, p;
  cin >> n >> p;
  vector<int> vec;
  vector<int> a(n);
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
    if (cnt[a[i]] == 0) vec.push_back(a[i]);
    ++cnt[a[i]];
  }
  if (p == 1) {
    for (int x : vec) cnt[x] = 0;
    cout << (n % 2 == 0 ? 0 : 1) << endl;
    return;
  }
  int diff = 0, pos = 0;
  sort(vec.begin(), vec.end(), greater<int>());
  n = (int)vec.size();
  while (pos < n) {
    if (cnt[vec[pos]] % 2 == 0) {
      pos++;
      continue;
    }
    int x = vec[pos];
    int nd = 1, is_good = 0;
    for (int position = pos + 1; position < n; position++) {
      int new_nd = func(nd, p, (x - vec[position]));
      if (new_nd == -1) {
        break;
      }
      if (new_nd <= cnt[vec[position]]) {
        cnt[vec[position]] -= new_nd;
        pos = position;
        is_good = 1;
        break;
      } else {
        nd = new_nd - cnt[vec[position]];
        x = vec[position];
      }
    }
    if (!is_good) {
      diff = binpow(p, vec[pos]);
      for (int i = pos + 1; i < n; i++) {
        sub(diff, mul_1(cnt[vec[i]], binpow(p, vec[i])));
      }
      break;
    }
  }
  cout << diff << endl;
  for (int x : vec) cnt[x] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test_case;
  cin >> test_case;
  while (test_case--) {
    solve();
  }
}
