func_code_string: #include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   long long poww(long long num, long long p) {     long long ret = 1;     while (p != 0) {       if (p & 1) {         ret = (ret * num) % mod;       }       num = (num * num) % mod;       p = p >> 1;     }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, p;       cin >> n >> p;       long long a[n];       for (int i = 0; i < n; i++) cin >> a[i];       if (p == 1) {         if (n % 2 == 1)           cout <<  1 n ;         else           cout <<  0 n ;         continue;       }       sort(a, a + n);       stack<pair<long long, long long> > st;       for (int i = n - 1; i >= 0; i--) {         if (st.size() == 0) {           st.push(make_pair(a[i], 1));         } else {           long long t1 = a[i];           long long cnt = 1;           while (true) {             pair<long long, long long> t2 = st.top();             if (t2.first > t1) {               st.push(make_pair(t1, cnt));               break;             } else if (t2.first == t1) {               st.pop();               if (st.size() == 0)                 break;               else {                 cnt = t2.second + 1;                 if (cnt == p) {                   cnt = 1;                   t1++;                 } else {                   st.push(make_pair(t1, cnt));                   break;                 }               }             }           }         }       }       if (st.size() == 0) {         cout << 0 <<   n ;       } else {         long long ans = 0;         while (st.size() != 1) {           pair<long long, long long> temp = st.top();           st.pop();           ans = (ans + (temp.second * poww(p, temp.first)) % mod) % mod;         }         pair<long long, long long> temp = st.top();         st.pop();         long long res = poww(p, temp.first);         res = (res - ans + mod) % mod;         cout << res <<   n ;       }     }   }   