for _ in range(int(input())): n, m = map(int, input().split()) if m == 1: print(0) elif n >= m: print(m // 2) else: l = m - n - 1 print(m // 2 - (m - n) + (2 + m - n) * l // 2 + l)