/* author: Kite_kuma created: 2021.06.18 21:40:04 */ // #ifdef LOCAL // #define _GLIBCXX_DEBUG // #endif #include using namespace std; #pragma region macros #define foa(s, v) for(auto &s : v) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define popcnt(n) __builtin_popcountll((long long)n) #define REPname(a, b, c, d, e, ...) e #define rep(...) REPname(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__) #define REP0(x) for(int Counter_in_rep_macro = 0; Counter_in_rep_macro < (x); ++Counter_in_rep_macro) #define REP1(i, x) for(int i = 0; i < (x); ++i) #define REP2(i, l, r) for(int i = (l); i < (r); ++i) #define REP3(i, l, r, c) for(int i = (l); i < (r); i += (c)) #define DREPname(a, b, c, d, e, ...) e #define drep(...) DREPname(__VA_ARGS__, DREP3, DREP2, DREP1)(__VA_ARGS__) #define DREP1(i, x) for(int i = (x)-1; i >= 0; --i) #define DREP2(i, l, r) for(int i = (r)-1; i >= (l); --i) #define DREP3(i, l, r, c) for(int i = (r)-1; i >= (l); i -= (c)) #pragma endregion #pragma region aliases using ll = long long; using ld = long double; using ull = unsigned long long; using vi = std::vector; using vvi = std::vector>; using vvvi = std::vector>>; using vll = std::vector; using vvll = std::vector; using vvvll = std::vector; using pii = std::pair; using pll = std::pair; template using V = std::vector; template using VV = V>; template using VVV = V>>; template using pqup = std::priority_queue, std::greater>; template using pqdn = std::priority_queue; #pragma endregion #pragma region constants const int inf = 1e9; const long long INF = 1e18; const long double pi = acos(-1); const char dl = '\n'; const char sp = ' '; int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const int mod_1000000007 = 1000000007; const int mod_998244353 = 998244353; #pragma endregion #pragma region basic_operation template inline bool in_range(T0 x, T1 lef, T2 rig) { return ((lef <= x) && (x < rig)); } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } void Yes(bool f = 1) { std::cout << (f ? "Yes" : "No") << '\n'; } void No() { std::cout << "No\n"; } void YES(bool f = 1) { std::cout << (f ? "YES" : "NO") << '\n'; } void NO() { std::cout << "NO\n"; } template void drop(T answer) { std::cout << answer << '\n'; exit(0); } void err(bool flag = true) { if(!flag) return; std::cout << -1 << '\n'; exit(0); } template void vout(std::vector const &v, bool vertically = 0) { if(vertically) { for(auto const &a : v) { std::cout << a << '\n'; } return; } for(auto it = v.begin(); it != v.end(); it++) { std::cout << (*it); if(it != v.end() - 1) { std::cout << ' '; } } std::cout << '\n'; return; } inline void print() { std::cout << '\n'; } template inline void print(T x) { std::cout << x << '\n'; return; } template void print(Head H, Tail... T) { std::cout << H << " "; print(T...); } template void add(std::vector &v, T val) { for(auto &a : v) a += val; return; } template T dup(T a, T b) { assert(b != 0); return (a + b - 1) / b; } template T greatest_lower_multiple(T x, T d) { if(d == 0) return 0; if(d < 0) d *= -1; T y = x % d; if(y < 0) y += d; return x - y; } template T least_upper_multiple(T x, T d) { return -greatest_lower_multiple(-x, d); } long long POW(long long a, long long n) { long long res = 1; while(n > 0) { if(n & 1) res = res * a; a = a * a; n >>= 1; } return res; } long long modpow(long long a, long long n, long long mod) { // a^n mod assert(n >= 0 && mod); if(mod == 1) return 0LL; long long res = 1; while(n > 0) { if(n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res < 0 ? res + mod : res; } // return x which satisfies a * x % mod == gcd(a, mod) // not (mod | a) long long modinv(long long a, long long mod) { long long b = mod, u = 1, v = 0; while(b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } u %= mod; if(u < 0) u += mod; return u; } template int lb(const std::vector &a, const T x) { return std::distance(a.begin(), std::lower_bound(a.begin(), a.end(), x)); } template int ub(const std::vector &a, const T x) { return std::distance(a.begin(), std::upper_bound(a.begin(), a.end(), x)); } template void unq_sort(std::vector &a) { std::sort(a.begin(), a.end()); a.erase(std::unique(a.begin(), a.end()), a.end()); } template std::vector press(std::vector &a) { auto vec = a; unq_sort(vec); std::vector ret; for(auto &v : a) ret.push_back(lb(vec, v)); return ret; } #pragma endregion #pragma region input #define VEC(type, name, size) \ vector name(size); \ scanner::INPUT(name) #define VVEC(type, name, h, w) \ vector> name(h, vector(w)); \ scanner::INPUT(name) #define INT(...) \ int __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LL(...) \ long long __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define STR(...) \ string __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define CHR(...) \ char __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define DBL(...) \ double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define LD(...) \ long double __VA_ARGS__; \ scanner::INPUT(__VA_ARGS__) #define TPL3(type0, type1, type2, name) \ std::tuple name; \ scanner::INPUT(name); #define TPL4(type0, type1, type2, type3, name) \ std::tuple name; \ scanner::INPUT(name); namespace scanner { template void scan(T &a) { std::cin >> a; } template void scan(std::pair &p) { scan(p.first); scan(p.second); } template void scan(std::tuple &p) { T0 t0; T1 t1; T2 t2; scan(t0); scan(t1); scan(t2); p = std::make_tuple(t0, t1, t2); } template void scan(std::tuple &p) { T0 t0; T1 t1; T2 t2; T3 t3; scan(t0); scan(t1); scan(t2); scan(t3); p = std::make_tuple(t0, t1, t2, t3); } template void scan(std::vector &a) { for(auto &i : a) scan(i); } void INPUT() {} template void INPUT(Head &head, Tail &... tail) { scan(head); INPUT(tail...); } } // namespace scanner template std::istream &operator>>(std::istream &is, std::pair &p) { is >> p.first >> p.second; return is; } #pragma endregion #pragma region debug #pragma region output template std::ostream &std::operator<<(std::ostream &os, const std::pair &p) { os << p.first << " " << p.second; return os; } template std::ostream &std::operator<<(std::ostream &os, const std::vector &v) { for(int i = 0; i < (int)v.size(); i++) { if(i) os << " "; os << v[i]; } return os; } #pragma endregion #pragma region view namespace viewer { void view(const long long e) { if(e == INF) std::cerr << "INF"; else if(e == -INF) std::cerr << "-INF"; else std::cerr << e; } void view(const int e) { if(e == inf) std::cerr << "inf"; else if(e == -inf) std::cerr << "-inf"; else std::cerr << e; } template void view(const T e) { std::cerr << e; } template void view(const std::pair &p) { std::cerr << "("; view(p.first); std::cerr << ", "; view(p.second); std::cerr << ")"; } template void view(const std::tuple &p) { std::cerr << "("; view(std::get<0>(p)); std::cerr << ", "; view(std::get<1>(p)); std::cerr << ", "; view(std::get<2>(p)); std::cerr << ")"; } template void view(const std::tuple &p) { std::cerr << "("; view(std::get<0>(p)); std::cerr << ", "; view(std::get<1>(p)); std::cerr << ", "; view(std::get<2>(p)); std::cerr << ", "; view(std::get<3>(p)); std::cerr << ")"; } template void view(const std::set &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::unordered_set &s) { if(s.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(auto &t : s) { view(t); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::vector &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << "{ "; for(const auto &e : v) { view(e); std::cerr << ", "; } std::cerr << "\b\b }"; } template void view(const std::vector> &vv) { std::cerr << "{\n"; for(const auto &v : vv) { std::cerr << "\t"; view(v); std::cerr << '\n'; } std::cerr << "}"; } template void view(const std::vector> &v) { std::cerr << "{\n"; for(const auto &c : v) { std::cerr << "\t("; view(c.first); std::cerr << ", "; view(c.second); std::cerr << ")\n"; } std::cerr << "}"; } template void view(const std::vector> &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << '{'; for(const auto &t : v) { std::cerr << "\n\t"; view(t); std::cerr << ","; } std::cerr << "\n}"; } template void view(const std::vector> &v) { if(v.empty()) { std::cerr << "{ }"; return; } std::cerr << '{'; for(const auto &t : v) { std::cerr << "\n\t"; view(t); std::cerr << ","; } std::cerr << "\n}"; } template void view(const std::map &m) { std::cerr << "{\n"; for(const auto &t : m) { std::cerr << "\t["; view(t.first); std::cerr << "] : "; view(t.second); std::cerr << '\n'; } std::cerr << "}"; } template void view(const std::unordered_map &m) { std::cerr << "{\n"; for(const auto &t : m) { std::cerr << "\t["; view(t.first); std::cerr << "] : "; view(t.second); std::cerr << '\n'; } std::cerr << "}"; } } // namespace viewer #pragma endregion // when debugging : g++ foo.cpp -DLOCAL #ifdef LOCAL void debug_out() {} template void debug_out(Head H, Tail... T) { viewer::view(H); std::cerr << ", "; debug_out(T...); } #define debug(...) \ do { \ std::cerr << __LINE__ << " [" << #__VA_ARGS__ << "] : ["; \ debug_out(__VA_ARGS__); \ std::cerr << "\b\b]\n"; \ } while(0) #define dump(x) \ do { \ std::cerr << __LINE__ << " " << #x << " : "; \ viewer::view(x); \ std::cerr << '\n'; \ } while(0) #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #pragma endregion #pragma region modint const int mod = mod_998244353; template struct ModInt { int x; ModInt() : x(0) {} ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(long long n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { long long t; is >> t; a = ModInt(t); return (is); } static int get_mod() { return mod; } }; using mint = ModInt; #pragma endregion #pragma region binomial_coefficient // normal binomial coefficient vector> binom_memo(100, vector(100, -1)); long long binom(int n, int k) { assert(n < 100 && k < 100); if(n < k || k < 0 || n < 0) return 0; if(binom_memo[n][k] != -1) return binom_memo[n][k]; long long res; if(n - k < k) res = binom(n, n - k); else if(k == 0) res = 1; else res = binom(n - 1, k - 1) + binom(n - 1, k); binom_memo[n][k] = res; return res; } vector fac, finv, inv; struct mod_factorial { const int MAX; // time: 300ms, when MAX = 3*10^7, time: 1900ms mod_factorial(const int MAX_ = 5100000) : MAX(MAX_) { fac.resize(MAX), finv.resize(MAX), inv.resize(MAX); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } } mod_factorial_; long long com_mod(long long n, long long k) { if(n < k || n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } long long permutation_mod(long long n, long long k) { if(n < k || n < 0 || k < 0) return 0; return fac[n] * finv[n - k] % mod; } // patterns of n of undistinguished balls in k of distinguished boxes long long multi_choose_mod(long long n, long long k) { return com_mod(n + k - 1, n); } #pragma endregion mint solve() { INT(n); INT(k); VEC(ll, a, n); ll s = accumulate(all(a), 0LL); vll b(n), c(n); int h = 0; pqdn> q; rep(i, n) { ll val = a[i] * k; b[i] = val / s; c[i] = val % s; h += b[i]; q.emplace(c[i], i); } while(h < k) { h++; int idx = q.top().second; q.pop(); b[idx]++; } // s = ; mint ans = fac[accumulate(all(b), 0LL)]; foa(t, b) ans *= finv[t]; rep(i,n){ ans *= (mint(a[i]) / s).pow(b[i]); } return ans; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); srand((unsigned)time(NULL)); INT(t); rep(t) { cout << solve() << dl; } return 0; }