/* -*- coding: utf-8 -*- * * 1252.cc: No.1252 数字根D - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ ll fm(int n, int d) { if (n <= 0) return 0; int k = n / (d - 1), r = n % (d - 1); return (ll)d * (d - 1) / 2 * k + (ll)r * (r + 1) / 2; } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int d, a, b; scanf("%d%d%d", &d, &a, &b); printf("%lld\n", fm(b, d) - fm(a - 1, d)); } return 0; }