t = int(input()) for _ in range(t): d, a, b = map(int, input().split()) num = b - a + 1 q, r = divmod(num, d - 1) ans = q * (d - 1) * d // 2 while a >= d: temp = 0 while a != 0: temp += a % d a //= d a = temp if a + r <= d: ans += r * (a + a + r - 1) // 2 else: e = (a + r) % d ans += (d - a) * (a + d - 1) // 2 ans += e * (1 + e) // 2 print(ans)