'''def solve():
    n, m = map(int, input().split())
    if n-m <= m:
        start = 2; end = 2 * (n - m) - 2
        res = (start + end) * (n - m - 1) + end + 2
        rest = m - (n - m)
        start = 2 * (n - m) + 1; end = n
        res += (start + end) * rest // 2
    else:
        start = 1; end = 2 * m - 1
        res = (start + end) * m
        rest = n - m - m
        res += rest * m * 2
    print(res)'''

def solve():
    n, m = map(int, input().split())
    res = n * (n + 1) // 2
    if n-m > m:
        res -= m
        rest = n-m-m
        res -= rest * (rest + 1) // 2
    print(res)
T = int(input())
for _ in range(T):
    solve()
