import math
def main():
    num = int(input())

    for _ in range(num):
        n, m = map(int, input().split())
        if m == 0:
            print(0)
            continue

        b = n - m
        a = n // 2
        if m == 1:
            d = math.ceil(n/2)
            ans = d ** 2
        elif a < b:
            ans = n * (n + 1) // 2
            d = math.ceil(n/2)
            amari = m - d
            ans -= amari * (amari + 1) * 2 + d

        else:
            ans = n * (n + 1) // 2
            ans -= b
        
        print(ans)


main()