// Problem: No.2793 Mancala Master // Group: yukicoder // URL: https://yukicoder.me/problems/no/2793 // Memory Limit: 512 MB // Time Limit: 2000 ms // Author: lingfunny // // Powered by CP Editor (https://cpeditor.org) #include using namespace std; using LL = long long; template constexpr T power(T a, LL b) { T res {1}; for (; b; b /= 2, a *= a) { if (b % 2) { res *= a; } } return res; } constexpr LL mul(LL a, LL b, LL p) { LL res = a * b - LL(1.L * a * b / p) * p; res %= p; if (res < 0) { res += p; } return res; } template struct MInt { LL x; constexpr MInt() : x {0} {} constexpr MInt(LL x) : x {norm(x % getMod())} {} static LL Mod; constexpr static LL getMod() { if (P > 0) { return P; } else { return Mod; } } constexpr static void setMod(LL Mod_) { Mod = Mod_; } constexpr LL norm(LL x) const { if (x < 0) { x += getMod(); } if (x >= getMod()) { x -= getMod(); } return x; } constexpr LL val() const { return x; } constexpr MInt operator-() const { MInt res; res.x = norm(getMod() - x); return res; } constexpr MInt inv() const { return power(*this, getMod() - 2); } constexpr MInt &operator*=(MInt rhs) & { if (getMod() < (1ULL << 31)) { x = x * rhs.x % int(getMod()); } else { x = mul(x, rhs.x, getMod()); } return *this; } constexpr MInt &operator+=(MInt rhs) & { x = norm(x + rhs.x); return *this; } constexpr MInt &operator-=(MInt rhs) & { x = norm(x - rhs.x); return *this; } constexpr MInt &operator/=(MInt rhs) & { return *this *= rhs.inv(); } friend constexpr MInt operator*(MInt lhs, MInt rhs) { MInt res = lhs; res *= rhs; return res; } friend constexpr MInt operator+(MInt lhs, MInt rhs) { MInt res = lhs; res += rhs; return res; } friend constexpr MInt operator-(MInt lhs, MInt rhs) { MInt res = lhs; res -= rhs; return res; } friend constexpr MInt operator/(MInt lhs, MInt rhs) { MInt res = lhs; res /= rhs; return res; } friend constexpr std::istream &operator>>(std::istream &is, MInt &a) { LL v; is >> v; a = MInt(v); return is; } friend constexpr std::ostream &operator<<(std::ostream &os, const MInt &a) { return os << a.val(); } friend constexpr bool operator==(MInt lhs, MInt rhs) { return lhs.val() == rhs.val(); } friend constexpr bool operator!=(MInt lhs, MInt rhs) { return lhs.val() != rhs.val(); } friend constexpr bool operator<(MInt lhs, MInt rhs) { return lhs.val() < rhs.val(); } }; template<> LL MInt<0>::Mod = 998244353; constexpr int P = 998244353; using Z = MInt

; const int mxn = 2e5 + 10; int a[mxn]; void solve() { int n, k; Z res = 1; cin >> n >> k; { Z cur = 1; for (int i = 1; i <= n; ++i) { cin >> a[i]; cur *= k; res *= cur - 1; } } { LL tot = 0; for (int i = 1; i <= n; ++i) tot += 1ll * i * (a[i] - 1); res *= power(Z(k), tot); } cout << res << '\n'; } int main() { int TestCase; for (scanf("%d", &TestCase); TestCase--;) solve(); return 0; } // f(x + y) - f(x + y - 1) = f(x)f(y) // k^{M-c}(k-1)^c