#include using namespace std; constexpr int mod = 998244353; bool dp[200200]; int main() { /* int X; // X は偶数 cin >> X; for(int i = 1; i <= 100; i++) { if(i < X) { if(i%2 == 1) { dp[i] = true; } continue; } if(i == X) { dp[i] = true; continue; } if(i == X+1) { continue; } if(!dp[i-1]) { dp[i] = true; continue; } if(i == 2*X) { continue; } if(dp[i-X-2]) { continue; } if(i < 2*X) { dp[i] = true; continue; } if(i == 2*X+1) { dp[i] = true; continue; } if(dp[2*X-2]) { dp[i] = true; } } for(int i = X; i <= 30; i++) { if(dp[i]) { cout << i << endl; } }*/ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while(t--) { long long n,x; cin >> n >> x; if(x%2 == 1) { cout << (n+1)/2%mod << "\n"; } else { if(n < x) { cout << (n+1)/2%mod << "\n"; } else { long long tmp = x/2+1; if(n >= x+2) { long long tmp2 = (x/2+1)*2+1; tmp += (n-x-2)/tmp2*(tmp2+1)/2; tmp += (n-x-2)%tmp2/2+1; } tmp %= mod; cout << tmp << "\n"; } } } }