#include<iostream> #include<cstring> #include<vector> usingnamespace std; using LL = longlong; template<constint T> structModInt { conststaticint mod = T; int x; ModInt(int x = 0) : x(x % mod) {} ModInt(longlong x) : x(int(x % mod)) {} intval(){ return x; } ModInt operator + (const ModInt &a) const { int x0 = x + a.x; returnModInt(x0 < mod ? x0 : x0 - mod); } ModInt operator - (const ModInt &a) const { int x0 = x - a.x; returnModInt(x0 < 0 ? x0 + mod : x0); } ModInt operator * (const ModInt &a) const { returnModInt(1LL * x * a.x % mod); } ModInt operator / (const ModInt &a) const { return *this * a.inv(); } booloperator == (const ModInt &a) const { return x == a.x; }; booloperator != (const ModInt &a) const { return x != a.x; }; voidoperator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; } voidoperator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; } voidoperator *= (const ModInt &a) { x = 1LL * x * a.x % mod; } voidoperator /= (const ModInt &a) { *this = *this / a; } friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; returnModInt(x0 < mod ? x0 : x0 - mod); } friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; returnModInt(x0 < 0 ? x0 + mod : x0); } friend ModInt operator * (int y, const ModInt &a){ returnModInt(1LL * y * a.x % mod);} friend ModInt operator / (int y, const ModInt &a){ returnModInt(y) / a;} friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;} friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}
ModInt pow(int64_t n)const{ ModInt res(1), mul(x); while(n){ if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; }
ModInt inv()const{ int a = x, b = mod, u = 1, v = 0; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += mod; return u; }
}; using mint = ModInt<1000000007>;
constint maxn = 2e5 + 5, mod = 1e9 + 7; mint inv[maxn]; voidinit(){ inv[1] = 1; for(int i = 2; i < maxn; i++) inv[i] = mint(mod - mod / i) * inv[mod % i]; }
intmain(){
cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
init(); int T; cin >> T; while(T--){ int n, m, k; cin >> n >> m >> k; for(int i = 0; i < n; i++){ int x; cin >> x; } if (k == 1){ cout << 1 << '\n'; continue; } mint ans = mint(k).pow(m); mint c = 1; for(int i = 0, j = m; i <= n - 1; i++, j--){ ans -= c * mint(k - 1).pow(m - i); c *= inv[i + 1] * j; } cout << ans << '\n'; }