func_code_string: #include <bits/stdc++.h>   using namespace std;   int a[1000001];   int mod = 1000000007;   int f(int x, int y) {     int res = 1;     long long xx = x;     while (y > 0) {       if (y % 2) res = (res * xx) % mod;       xx = (xx * xx) % mod;       y = y / 2;     }     return res;   }   int main() {     int t, p;     int n, ba;     int i, j;     scanf( %d , &t);     for (p = 1; p <= t; p++) {       scanf( %d%d , &n, &ba);       for (i = 1; i <= n; i++) scanf( %d , &a[i]);       if (ba == 1) {         printf( %d n , n % 2);         continue;       }       sort(a + 1, a + n + 1);       long long cur = 1;       for (i = n - 1; i >= 1; i--) {         if (a[i] == a[i + 1]) {           if (cur == 0)             cur++;           else             cur--;         } else {           if (cur == 0)             cur++;           else {             while (a[i + 1] > a[i] && cur < i) {               a[i + 1]--;               cur = cur * ba;             }             if (cur < i)               cur--;             else               break;           }         }       }       if (i == 0)         printf( %d n , (cur * f(ba, a[1])) % mod);       else {         int res = (cur * f(ba, a[i + 1])) % mod;         for (; i >= 1; i--) res = ((res - f(ba, a[i])) % mod + mod) % mod;         printf( %d n , res);       }     }     return 0;   }   