func main() var t: int :: cui@inputInt() for(0, t - 1) var d: int :: cui@inputInt() var a: int :: cui@inputInt() var b: int :: cui@inputInt() var ans: int :: 0 do ans :+ (b - a + 1) / (d - 1) * d * (d - 1) / 2 var start: int :: f(a, d) var dd: int :: d - 1 for i(start, start + (b - a + dd) % dd) do ans :+ 1 + (i + dd - 1) % dd end for do cui@print("\{ans}\n") func f(a: int, d: int): int var res: int :: 0 while(a <> 0) do res :+ a % d do a :/ d end while if(res >= d) ret f(res, d) else ret res end if end func end for end func