#include using namespace std; #define int long long #define ii pair #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20); #endif auto mod = [&] (int n, int m) { if (n % m == 0) return m; else return n % m; }; int t; cin >> t; auto f = [&] (int n, int d) { int ans = 0; while (n) { ans += n % d; n /= d; } return ans; }; auto sum = [&] (int n) { return n * (n + 1) / 2; }; auto solve = [&] (int d, int n) { if (n <= 0) return 0ll; int c = n/(d-1); int rem = n % (d - 1); return c * sum(d - 1) + sum(rem); /* int ans = 0; for (int i = 1; i <= n; ++i) { ans += mod(i, d - 1); } return ans; */ }; while (t--) { int d, l, r; cin >> d >> l >> r; cout << solve(d, r) - solve(d, l - 1) << endl; } }