lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end def tri(x) x * (x + 1) // 2 end def calc(x, d) x < 0 ? 0i64 : tri(d.pred) * (x // d.pred) + tri(x % d.pred) end read_line.to_i.times do d, a, b = read_line.split.map(&.to_i64) puts calc(b, d) - calc(a - 1, d) end