T = gets.to_i T.times do n, m = gets.split.map(&:to_i) if n < m if 2 * n - 1 < m puts (n - 1) * (3 + n + 1) / 2 else r = m - n l = n - r puts (r - 1) * (3 + r + 1) / 2 + l / 2 end else if m.even? puts (m - 1) / 2 + 1 else puts m / 2 end end end