#include using namespace std; using ll = long long; const int mod = 998244353; const int maxn = 10000010; int inv[maxn], f[maxn]; int main(void) { //freopen("b.in", "r", stdin); int N = 10000000; inv[1] = 1; for (int i=2; i<=N; i++) inv[i] = (mod - (mod / i) * (ll)inv[mod % i] % mod) % mod; int T; scanf("%d", &T); while (T--) { int n, c; scanf("%d%d", &n, &c); int A = 2ll * (c + 1) % mod, B = (4ll * c * c) % mod; f[0] = 1, f[1] = A; int ret = A; for (int i=2; i<=n; i++) { int tmp = (A * (ll)(2 * i - 1) % mod * f[i - 1] % mod - B * (ll)(i - 1) % mod * f[i - 2] % mod + mod) % mod; f[i] = inv[i] * (ll)tmp % mod; ret ^= f[i]; } printf("%d\n", ret); } return 0; }