#include using namespace std; using ll = long long; ll g(ll N, ll D, ll mod) { ll ans = 0; ll Q, R; if (N == 0) { return 0; } if (N % (D - 1) == 0) { Q = N / (D - 1); R = 0; } else { Q = N / (D - 1) + 1; R = D - 1 - N % (D - 1); } ll E, F, G, H; E = ((D * (D - 1)) / 2) % mod; E = (Q * E) % mod; F = (D * R) % mod; F = mod - F; G = ((R * (R + 1)) / 2) % mod; H = (E + F + G) % mod; return H; } ll max(ll a, ll b) { if (a >= b) { return a; } else { return b; } } int main() { ll T; ll D, A, B; ll P, Q; ll Mod = 1000000007; cin >> T; for (int i = 0; i < T; i++) { cin >> D >> A >> B; P = g(B, D, Mod); Q = g(max(A - 1, 0), D, Mod); Q = Mod - Q; cout << (P + Q) % Mod << endl; } return 0; }