#include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) using m32 = atcoder::modint998244353; m32 dp[4001][4001]; /* int main(){ int x,y; cin >> x >> y; if(4000 < x || 4000 < y) exit(0); dp[x][y] = 1; m32 ans = 0; for(int xx=x; xx>=0; xx--) for(int yy=y; yy>=0; yy--){ m32 p = dp[xx][yy]; if(xx == yy) ans += p; if(xx != 0) dp[xx-1][yy] += p; if(yy != 0) dp[xx][yy-1] += p; if(xx != 0 && yy != 0) dp[xx-1][yy-1] += p * 2; } cout << ans.val() << endl; return 0; } */ int main(){ const int z = 4000; dp[0][0] = 1; rep(xx,z+1) rep(yy,z+1){ if(xx != z) dp[xx+1][yy] += dp[xx][yy]; if(yy != z) dp[xx][yy+1] += dp[xx][yy]; if(xx != z && yy != z) dp[xx+1][yy+1] += dp[xx][yy] * 2; } rep(xx,z) rep(yy,z) dp[xx+1][yy+1] += dp[xx][yy]; int Q; cin >> Q; while(Q--){ int x,y; cin >> x >> y; cout << dp[x][y].val() << "\n"; } return 0; } struct ios_do_not_sync { ios_do_not_sync() { ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;