#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using i64 = long long;
using i32 = int;
using f64 = long double;
template <class Key>
using vec = vector<Key>;
template <class Key>
using hash_set = unordered_set<Key>;
template <class Key, class Value>
using hash_map = unordered_map<Key, Value>;
using str = string;
template <size_t Size1>
using a64 = array<i32, Size1>;
template <size_t Size1, size_t Size2>
using aa64 = array<a64<Size2>, Size1>;
using p64 = pair<i32, i32>;
using v64 = vec<i32>;
using vv64 = vec<v64>;
using s64 = set<i32>;
using m64 = map<i32, i32>;
mt19937 gen(998244353);
const i32 inf = numeric_limits<i32>::max() / 2;
template <class T>
inline i32 len(const T& a) {
  return (i32)(a.size());
}
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T, class S>
inline bool check_max(T& a, S b) {
  if (a < b) return a = b, 1;
  return 0;
}
void read() {}
void print() {}
void println() { cout << "\n"; }
template <class T, class... U>
void read(T& a, U&... b) {
  cin >> a;
  read(b...);
}
template <class T, class... U>
void print(const T& a, const U&... b) {
  cout << a << " ";
  print(b...);
}
template <class T, class... U>
void println(const T& a, const U&... b) {
  cout << a << " ";
  println(b...);
}
struct Problem {
  void files(str in, str out) {
    freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
  }
  void solve(), input();
  void many() {
    i32 t;
    read(t);
    while (t--) input(), solve();
  }
  void make(bool mt = 0) {
    if (mt)
      many();
    else
      input(), solve();
  }
} problem;
signed main() {
  fast();
  problem.make(1);
  return 0;
}
const i32 R = 1e9 + 7;
i32 n, p;
v64 a;
i32 binary_power(i32 a, i32 n, i32 R) {
  a %= R;
  if (n == 0) return 1;
  i32 ans = binary_power(a, n / 2, R);
  ans = ans * 1ll * ans % R;
  if (n % 2 == 1) ans = ans * 1ll * a % R;
  return ans;
}
void Problem::solve() {
  sort((a).begin(), (a).end(), greater<i32>());
  v64 rs;
  rs.push_back(R);
  for (i32 i = 0; i < 2; i++) {
    rs.push_back(gen() % i32(1e9) + 1);
  }
  v64 ss(len(rs));
  for (int(i) = 0; (i) < (n); (i)++) {
    i32 f = 1;
    for (int(j) = 0; (j) < (len(ss)); (j)++) {
      if (ss[j] != 0) {
        f = 0;
        break;
      }
    }
    if (!f) {
      for (int(j) = 0; (j) < (len(ss)); (j)++) {
        i32 x = binary_power(p, a[i], rs[j]);
        ss[j] = (0ll + ss[j] - x + rs[j]) % rs[j];
      }
    } else {
      for (int(j) = 0; (j) < (len(ss)); (j)++) {
        i32 x = binary_power(p, a[i], rs[j]);
        ss[j] = (0ll + ss[j] + x) % rs[j];
      }
    }
  }
  println(ss[0]);
}
void Problem::input() {
  read(n, p);
  a.assign(n, 0);
  for (int(i) = 0; (i) < (n); (i)++) {
    read(a[i]);
  }
}

### Prompt

Please formulate a Cpp solution to the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using i64 = long long;
using i32 = int;
using f64 = long double;
template <class Key>
using vec = vector<Key>;
template <class Key>
using hash_set = unordered_set<Key>;
template <class Key, class Value>
using hash_map = unordered_map<Key, Value>;
using str = string;
template <size_t Size1>
using a64 = array<i32, Size1>;
template <size_t Size1, size_t Size2>
using aa64 = array<a64<Size2>, Size1>;
using p64 = pair<i32, i32>;
using v64 = vec<i32>;
using vv64 = vec<v64>;
using s64 = set<i32>;
using m64 = map<i32, i32>;
mt19937 gen(998244353);
const i32 inf = numeric_limits<i32>::max() / 2;
template <class T>
inline i32 len(const T& a) {
  return (i32)(a.size());
}
inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
template <class T, class S>
inline bool check_min(T& a, S b) {
  if (a > b) return a = b, 1;
  return 0;
}
template <class T, class S>
inline bool check_max(T& a, S b) {
  if (a < b) return a = b, 1;
  return 0;
}
void read() {}
void print() {}
void println() { cout << "\n"; }
template <class T, class... U>
void read(T& a, U&... b) {
  cin >> a;
  read(b...);
}
template <class T, class... U>
void print(const T& a, const U&... b) {
  cout << a << " ";
  print(b...);
}
template <class T, class... U>
void println(const T& a, const U&... b) {
  cout << a << " ";
  println(b...);
}
struct Problem {
  void files(str in, str out) {
    freopen(in.c_str(), "r", stdin), freopen(out.c_str(), "w", stdout);
  }
  void solve(), input();
  void many() {
    i32 t;
    read(t);
    while (t--) input(), solve();
  }
  void make(bool mt = 0) {
    if (mt)
      many();
    else
      input(), solve();
  }
} problem;
signed main() {
  fast();
  problem.make(1);
  return 0;
}
const i32 R = 1e9 + 7;
i32 n, p;
v64 a;
i32 binary_power(i32 a, i32 n, i32 R) {
  a %= R;
  if (n == 0) return 1;
  i32 ans = binary_power(a, n / 2, R);
  ans = ans * 1ll * ans % R;
  if (n % 2 == 1) ans = ans * 1ll * a % R;
  return ans;
}
void Problem::solve() {
  sort((a).begin(), (a).end(), greater<i32>());
  v64 rs;
  rs.push_back(R);
  for (i32 i = 0; i < 2; i++) {
    rs.push_back(gen() % i32(1e9) + 1);
  }
  v64 ss(len(rs));
  for (int(i) = 0; (i) < (n); (i)++) {
    i32 f = 1;
    for (int(j) = 0; (j) < (len(ss)); (j)++) {
      if (ss[j] != 0) {
        f = 0;
        break;
      }
    }
    if (!f) {
      for (int(j) = 0; (j) < (len(ss)); (j)++) {
        i32 x = binary_power(p, a[i], rs[j]);
        ss[j] = (0ll + ss[j] - x + rs[j]) % rs[j];
      }
    } else {
      for (int(j) = 0; (j) < (len(ss)); (j)++) {
        i32 x = binary_power(p, a[i], rs[j]);
        ss[j] = (0ll + ss[j] + x) % rs[j];
      }
    }
  }
  println(ss[0]);
}
void Problem::input() {
  read(n, p);
  a.assign(n, 0);
  for (int(i) = 0; (i) < (n); (i)++) {
    read(a[i]);
  }
}

```