求助, 10 pts过不去了
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int SIZE = 2e7 + 5;
const int G = 3, mod = 998244353, Gi = 332748118;
int N, M, S, L, n, m, k;
int fac[SIZE], inv[SIZE], f[SIZE], g[SIZE], pos[SIZE];
namespace GTR {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t = buf;
inline int fetch() {
if (s == t) { t = (s = buf) + fread(buf, 1, bufl, stdin); if (s == t) return EOF; }
return *s++;
}
inline int read() {
int a = 0, b = 1, c = fetch();
while (c < 48 || c > 57) b ^= c == '-', c = fetch();
while (c >= 48 && c <= 57) a = (a << 1) + (a << 3) + c - 48, c = fetch();
return b ? a : -a;
}
}
using GTR::read;
int qPow(int a, int b) {
int ans = 1;
for ( ; b; b >>= 1, a = a * a % mod) {
if (b & 1) ans = ans * a % mod;
}
return ans % mod;
}
namespace poly {
int N = 1, M = 2, len = 0, pos[SIZE << 1];
void init(int l) {
M = l, N = 1, len = 0;
for ( ; N <= M; ++ len, N <<= 1);
for (int i = 0; i < N; ++ i) pos[i] = (pos[i >> 1] >> 1 | ((i & 1) << (len - 1)));
}
void NTT(int *a, int opt) {
int w, wn, t, *a0, *a1;
for (int i = 0; i < N; ++ i) if (i < pos[i]) std::swap(a[i], a[pos[i]]);
for (int i = 1, j, k; i < N; i <<= 1)
for (wn = qPow(opt == 1 ? G : Gi, (mod - 1) / (i << 1)), j = 0; j < N; j += (i << 1))
for (w = 1, k = 0, a1 = i + (a0 = a + j); k < i; ++ k, ++ a0, ++ a1, (w *= wn) %= mod)
t = *a1 * w % mod, *a1 = (*a0 - t + mod) % mod, (*a0 += t) %= mod;
if (opt == 1) return;
int inv = qPow(N, mod - 2);
for (int i = 0; i <= N; ++ i) f[i] = f[i] * inv % mod;
}
}
signed main() {
// freopen("code.in", "r", stdin);
N = read(), M = read(), S = read(), L = read(), fac[0] = 1ll;
int mx = std::max(L, n);
for (int i = 1; i <= mx; ++ i) fac[i] = fac[i - 1] * i % mod;
inv[mx] = qPow(fac[mx], mod - 2ll);
for (int i = mx - 1; ~i; -- i) inv[i] = inv[i + 1] * (i + 1ll) % mod;
for (int i = 0; i <= L; ++ i) {
if (i & 1) f[i] = (mod - inv[i] + mod) % mod; else f[i] = inv[i];
g[i] = qPow(i, L) * inv[i] % mod;
}
poly::init(2 * L); poly::NTT(f, 1), poly::NTT(g, 1);
for (int i = 0; i <= poly::N; ++ i) f[i] = f[i] * g[i] % mod;
poly::NTT(f, -1); fac[0] = 1ll;
while (S --) {
n = read(), m = read(), k = read();
int len = std::min(L, std::min(m, std::min(n, k))), ans = 0ll;
for (int i = 0; i <= len; ++ i)
ans = (ans + (f[i] * inv[m - i] % mod * fac[n - i] % mod * inv[k - i] % mod)) % mod;
ans = (ans * (fac[m] * inv[n] % mod * fac[k] % mod)) % mod;
printf("%lld\n", ans % mod);
}
}