#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int k[1000010];   long long qpow(long long x, int n) {     long long ans = 1;     for (; n; n >>= 1, x = x * x % mod)       if (n & 1) ans = ans * x % mod;     return ans;   }   long long lpow(long long x, int n) {     long long ans = 1;     for (; n; n >>= 1, x *= x) {       if (n && x > mod) return mod;       if (n & 1) ans *= x;       if (ans > mod) return mod;     }     return ans;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, p;       scanf( %d%d , &n, &p);       for (int i = 0; i < n; i++) scanf( %d , &k[i]);       sort(k, k + n);       long long d = 0;       long long sl = 0, sr = 0, q = k[n - 1];       for (int i = n - 1; i >= 0; i--) {         if (q > k[i]) {           sl = sl * qpow(p, q - k[i]) % mod;           sr = sr * qpow(p, q - k[i]) % mod;           d = min(d * lpow(p, q - k[i]), mod);           q = k[i];         }         if (d)           d--, sr++;         else           d++, sl++;       }       sl = sl * qpow(p, q) % mod;       sr = sr * qpow(p, q) % mod;       printf( %lld n , (sl - sr + mod) % mod);     }   }   