#include using namespace std; using ll = long long; using P = pair; #define fix(x) fixed << setprecision(x) #define asc(x) x, vector, greater #define rep(i, n) for(ll i = 0; i < n; i++) #define all(x) (x).begin(),(x).end() templatebool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;} templatebool chmax(T&a, const T&b){if(a> t; while(t--){ ll n,m,l,r; cin >> n >> m >> l >> r; n--; ll v = r-l+1, z = r/n + (m-l)/n + 1; ll ans = (v%MOD)*(z%MOD)%MOD; ll x,y; x = l%n-n, y = l-r/n*n; ans += ((x+y)%MOD) * (((x-y)/n+1)%MOD) % MOD * inv2 % MOD; l = abs(l-m), r = abs(r-m); swap(l,r); x = l%n-n, y = l-r/n*n; ans += ((x+y)%MOD) * (((x-y)/n+1)%MOD) % MOD * inv2 % MOD; cout << (ans%MOD+MOD)%MOD << '\n'; } return 0; }