#include #include #include #include using namespace std; using ll=long long; using mint=atcoder::modint998244353; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} mint f(ll N,ll M,ll X){ if(X<0)return 0; ll d=M%N; mint ans=0; mint K=M/N,P=(X/N)*(d+1); if(X%Nd)Q+=X%N-d-1; ans+=(L+1)*Q; return ans; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin>>T; while(T--){ ll N,M,L,R; cin>>N>>M>>L>>R; N--; mint ans=f(N,M,R)-f(N,M,L-1); cout<