#include #include #include #include #include using namespace std; constexpr int M = 998244353; long long modexp(int x, long long e, int m) { long long ans = 1, p = x % m; while (e > 0) { if (e % 2 != 0) ans = (ans * p) % m; p = (p * p) % m; e >>= 1; } return ans; } class ModComb { long long *fact, *facti; const int mod; public: explicit ModComb(int n, int m) : mod(m) { fact = new long long[n+1]; facti = new long long[n+1]; fact[0] = 1; facti[0] = 1; for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % m; // calc 1/n! long long &inv = facti[n], pw = fact[n]; inv = 1; for (int e = mod-2; e > 0; e /= 2) { if (e&1) inv = inv * pw % mod; pw = pw * pw % mod; } for (int i = n-1; i > 0; i--) facti[i] = (facti[i+1] * (i+1)) % m; } ~ModComb() { if (fact) delete[] fact; if (facti) delete[] facti; } long long getFact(int n) const { return fact[n]; } long long getFactInv(int n) const { return facti[n]; } long long getComb(int n, int k) const { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * facti[k] % mod * facti[n-k] % mod; } long long getPerm(int n, int k) const { if (n < 0 || k < 0 || k > n) return 0; return fact[n] * facti[n-k] % mod; } }; int main() { int t; cin >> t; ModComb mc(100100, M); while (t--) { int n, k; cin >> n >> k; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; struct entry { int i, m, a; entry(int i, int m, int a) : i(i), m(m), a(a) {} bool operator<(const entry& rhs) const { return a * rhs.m < rhs.a * m; } }; priority_queue pq; for (int i = 0; i < n; i++) pq.emplace(i, 1, a[i]); vector f(n); int sum = 0; while (sum < k) { auto [i, m, a] = pq.top(); pq.pop(); sum++; f[i]++; assert(f[i] == m); pq.emplace(i, m+1, a); } long long p = modexp(accumulate(a.begin(), a.end(), 0), M-k-1, M); int s = k; for (int i = 0; i < n; i++) { p = p * mc.getComb(s, f[i]) % M; p = p * modexp(a[i], f[i], M) % M; s -= f[i]; } assert(s == 0); cout << p << endl; } }