#include #include using namespace std; using ll = long long; const ll MOD = 998244353; void solve() { ll N, M, L, R; cin >> N >> M >> L >> R; ll ans = (R - L + 1) % MOD; ans *= ((M - L) / (N - 1) + 1) % MOD; ans %= MOD; cout << ans << endl; } int main() { int T; cin >> T; while(T--) solve(); return 0; }