def oi(): return int(input()) def os(): return input() def mi(): return list(map(int, input().split())) m = 998244353 def f(A, B): if (A < 0): return 0 q = A//B r = A % B q %= m r %= m return ((q*(q-1)//2) % m * B % m + q * (r+1) % m) % m T = oi() for i in range(T): N, M, L, R = mi() ans = (R-L+1) % m ans += f(R, N-1) ans -= f(L-1, N-1) ans += f(M-L, N-1) ans -= f(M-R-1, N-1) ans %= m ans += m ans %= m print(ans)