#include #include #define RANGE_SIZE 450 int cmp_mo (const void *a, const void *b) { int *a_ = (int *)a; int *b_ = (int *)b; if (a_[0]/RANGE_SIZE < b_[0]/RANGE_SIZE) { return -1; } if (a_[0]/RANGE_SIZE > b_[0]/RANGE_SIZE) { return 1; } if (a_[1] < b_[1]) { return -1; } if (a_[1] > b_[1]) { return 1; } return 0; } long long power_mod (long long a, long long b, long long mod_num) { long long ans = 1LL; if (b > 0LL) { ans = power_mod(a, b/2LL, mod_num); ans = (ans * ans) % mod_num; if (b%2LL == 1LL) { ans = (ans * (a % mod_num)) % mod_num; } } return ans; } int main () { int t = 0; int nm[200000][3] = {}; int res = 0; long long ans[200000] = {}; long long mod_num = 998244353LL; long long fact[400001] = {}; long long invf[400001] = {}; long long inv2 = (mod_num+1LL)/2LL; res = scanf("%d", &t); for (int i = 0; i < t; i++) { res = scanf("%d", nm[i]); res = scanf("%d", nm[i]+1); nm[i][2] = i; } fact[0] = 1LL; for (int i = 0; i < 400000; i++) { fact[i+1] = fact[i]; fact[i+1] *= (long long)(i+1); fact[i+1] %= mod_num; } invf[400000] = power_mod(fact[400000], mod_num-2LL, mod_num); for (int i = 400000; i > 0; i--) { invf[i-1] = invf[i]; invf[i-1] *= (long long)i; invf[i-1] %= mod_num; } for (int i = 0; i < nm[0][1]; i++) { if (2*i >= nm[0][0]-1) { long long tmp = (fact[2*i]*invf[nm[0][0]-1])%mod_num; ans[nm[0][2]] += (tmp*invf[2*i-nm[0][0]+1])%mod_num; } } ans[nm[0][2]] %= mod_num; qsort(nm, t, sizeof(int)*3, cmp_mo); for (int i = 1; i < t; i++) { int pn = nm[i-1][0]; int pm = nm[i-1][1]; ans[nm[i][2]] = ans[nm[i-1][2]]; while (pn != nm[i][0] || pm != nm[i][1]) { if (pn < nm[i][0]) { long long tmp = 0LL; if (2*pm > pn) { tmp = (fact[2*pm]*invf[pn+1])%mod_num; tmp = (tmp*invf[2*pm-pn-1])%mod_num; } ans[nm[i][2]] = (tmp+mod_num-ans[nm[i][2]])%mod_num; ans[nm[i][2]] *= inv2; ans[nm[i][2]] %= mod_num; pn++; } else if (pn > nm[i][0]) { long long tmp = 0LL; if (2*pm >= pn) { tmp = (fact[2*pm]*invf[pn])%mod_num; tmp = (tmp*invf[2*pm-pn])%mod_num; } ans[nm[i][2]] = (tmp+2LL*mod_num-2LL*ans[nm[i][2]])%mod_num; pn--; } else if (pm < nm[i][1]) { if (2*pm >= pn-1) { long long tmp = (fact[2*pm]*invf[pn-1])%mod_num; ans[nm[i][2]] += tmp*invf[2*pm-pn+1]; ans[nm[i][2]] %= mod_num; } pm++; } else { if (2*pm-2 >= pn-1) { long long tmp = (fact[2*pm-2]*invf[pn-1])%mod_num; ans[nm[i][2]] += mod_num-(tmp*invf[2*pm-pn-1])%mod_num; ans[nm[i][2]] %= mod_num; } pm--; } } } for (int i = 0; i < t; i++) { printf("%lld\n", ans[i]); } return 0; }