#include #include #include using namespace std; using mint=atcoder::modint998244353; int T,N,K; int A[1<<17]; mint inv[1<<17]; main() { cin>>T; inv[1]=1; for(int i=2;i<1<<17;i++)inv[i]=-(998244353/i)*inv[998244353%i]; for(;T--;) { cin>>N>>K; int sum=0; priority_queue > >P; for(int i=0;i>A[i]; P.push(make_pair(A[i]*K,make_pair(0,A[i]))); sum+=A[i]; } mint ans=1,invsum=mint(1)/sum; for(int i=1;i<=K;i++) { ans*=i; pair >p=P.top();P.pop(); p.first-=sum; p.second.first--; P.push(p); ans*=inv[-p.second.first]; ans*=p.second.second*invsum; } cout<