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;
namespace input {
template <class T>
void scan(T& x) {
  cin >> x;
}
template <class T>
void scan_iter(const T& begin, const T& end) {
  for (T it = begin; it != end; it++) {
    scan(*it);
  }
}
template <class T, class... Ts>
void scan(T& t, Ts&... ts) {
  scan(t);
  scan(ts...);
}
template <class T1, class T2>
void scan(pair<T1, T2>& p) {
  scan(p.first, p.second);
}
template <class T>
void scan(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) scan(a[i]);
}
template <class T>
void cscan(T& x) {}
void cscan(int& x) { scanf("%d", &x); }
void cscan(long long& x) { scanf("%lld", &x); }
void cscan(double& x) { scanf("%lf", &x); }
void cscan(char* x) { scanf("%s", x); }
template <class T>
void cscan_iter(const T& begin, const T& end) {
  for (T it = begin; it != end; it++) {
    cscan(*it);
  }
}
template <class T, class... Ts>
void cscan(T& t, Ts&... ts) {
  cscan(t);
  cscan(ts...);
}
template <class T1, class T2>
void cscan(pair<T1, T2>& p) {
  cscan(p.first, p.second);
}
template <class T>
void cscan(vector<T>& a) {
  for (int i = 0; i < a.size(); i++) cscan(a[i]);
}
}  // namespace input
using namespace input;
namespace output {
void print(int x) { cout << x; }
void print(size_t x) { cout << x; }
void print(long long x) { cout << x; }
void print(double x) { cout << x; }
void print(const char* x) { cout << x; }
void print(const string& x) { cout << x; }
template <class T, class... Ts>
void print(const T& t, const Ts&... ts) {
  print(t);
  if (sizeof...(ts)) print(" ");
  print(ts...);
}
template <class T1, class T2>
void print(const pair<T1, T2>& x) {
  print(x.first, x.second);
}
template <class T>
void print_iter(const T& begin, const T& end) {
  bool first = true;
  for (T it = begin; it != end; it++) {
    if (!first) print(" ");
    print(*it);
    first = false;
  }
}
template <class T>
void print(const initializer_list<T>& x) {
  print_iter(x.begin(), x.end());
}
template <class T>
void print(const vector<T>& x) {
  print_iter(x.begin(), x.end());
}
void print() { print("\n"); }
template <class T>
void println(const T& x) {
  print(x);
  print();
}
void cprint(int x) { printf("%d", x); }
void cprint(size_t x) { printf("%zd", x); }
void cprint(long long x) { printf("%lld", x); }
void cprint(double x) { printf("%lf", x); }
void cprint(char* x) { printf("%s", x); }
void cprint(const char* x) { printf("%s", x); }
void cprint(const string& x) { cprint(x.c_str()); }
template <class T, class... Ts>
void cprint(const T& t, const Ts&... ts) {
  cprint(t);
  if (sizeof...(ts)) cprint(" ");
  cprint(ts...);
}
template <class T1, class T2>
void cprint(const pair<T1, T2>& x) {
  cprint(x.first, x.second);
}
template <class T>
void cprint_iter(const T& begin, const T& end) {
  bool first = true;
  for (T it = begin; it != end; it++) {
    if (!first) cprint(" ");
    cprint(*it);
    first = false;
  }
}
template <class T>
void cprint(const initializer_list<T>& x) {
  cprint_iter(x.begin(), x.end());
}
template <class T>
void cprint(const vector<T>& x) {
  cprint_iter(x.begin(), x.end());
}
void cprint() { cprint("\n"); }
template <class T>
void cprintln(const T& x) {
  cprint(x);
  cprint();
}
}  // namespace output
using namespace output;
const int maxn = 1000000 + 5;
const long long mod = 1000000000 + 7;
long long k[maxn];
long long pow_mod(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res;
}
int main(void) {
  int t;
  cscan(t);
  while (t--) {
    int n;
    long long p;
    cscan(n, p);
    cscan_iter(k + 1, k + n + 1);
    if (n == 1) {
      cprintln(pow_mod(p, k[1]));
    } else {
      sort(k + 1, k + n + 1);
      reverse(k + 1, k + n + 1);
      long long left = -1;
      long long cnt = 0;
      bool finish = false;
      for (int i = 1; i <= n;) {
        int j = i;
        for (; j <= n && k[j] == k[i]; j++)
          ;
        long long right = k[i];
        long long cnt2 = j - i;
        if (cnt != 0) {
          if (log(cnt) + (left - right) * log(p) > log(n)) {
            finish = true;
          } else {
            cnt *= pow_mod(p, left - right);
            left = right;
          }
          if (finish) {
            long long val1 = pow_mod(p, left) * (cnt % mod) % mod;
            long long val2 = 0;
            while (i <= n) {
              val2 = (val2 + pow_mod(p, k[i])) % mod;
              i++;
            }
            cprintln((val1 - val2 + mod) % mod);
            break;
          }
        }
        i = j;
        if (cnt > cnt2) {
          cnt -= cnt2;
        } else {
          cnt2 -= cnt;
          if (cnt2 % 2 == 1) {
            left = right;
            cnt = 1;
          } else {
            cnt = 0;
          }
        }
      }
      if (!finish) {
        if (cnt == 0) {
          cprintln(0);
        } else {
          cprintln(pow_mod(p, left) * (cnt % mod) % mod);
        }
      }
    }
  }
  return 0;
}
