mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline for _ in range(int(input())): N, M = map(int, input().split()) if M == 1: print(0) continue if M <= N: print((M + 1) // 2) elif M == 2 * N: print(N - 1 + N * (N + 1) // 2 - 1) else: K = M - N - 1 if K == 0: print((N - K + 1) // 2) elif K == 1: print((N - K + 1) // 2 + 3) else: print((N - K + 1) // 2 + K + (K + 1) * (K + 2) // 2 - 1) if __name__ == '__main__': main()