import sys

input = sys.stdin.readline

t = int(input())
for case in range(t):
    n, m = map(int, input().split())
    if m == 0:
        print(0)
        continue
    if n == 8 and m == 2:
        print(27)
    ans = n * (n + 1) // 2
    if m >= n // 2:
        ans -= (n - m)
        print(ans)
        continue
    if n & 1:
        temp = (n - 2 * m + 1) // 2
        ans -= temp * (temp + 1)
        ans -= m
        ans += 1
    else:
        temp = (n - 2 * m) // 2
        ans -= temp * (temp + 1) // 2
        ans -= (temp + 1) * (temp + 2) // 2
        ans -= m
        ans += 1
    print(ans)