#include #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; template bool chkmax(T &x,T y){return x bool chkmin(T &x,T y){return x>y?x=y,true:false;} int readint(){ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const int cys=998244353,N=10000000; int n,c; ll a[10000005],ds[10000005]; ll qpow(ll x,ll p){ ll ret=1; for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys; return ret; } int main(){ int T=readint(); ds[1]=1; for(int i=2;i<=N;i++) ds[i]=(cys-cys/i)*ds[cys%i]%cys; while(T--){ n=readint(); c=readint(); a[0]=1; a[1]=(c+c+2)%cys; ll tmp=1ll*(c+c)*(c+c)%cys,ans=a[1]; for(int i=2;i<=n;i++){ a[i]=(a[i-1]*(c+c+2)%cys*(i+i-1)-tmp*(i-1)%cys*a[i-2])%cys; if(a[i]<0) a[i]+=cys; a[i]=a[i]*ds[i]%cys; ans^=a[i]; } printf("%lld\n",ans); } return 0; }