import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
    N, M = map(int, input().split())
    if M < N//2:
        print((N*(N+1))//2 - (M + ((N-2*M)*(N-2*M+1)//2)))
    else:
        print((N*(N+1))//2 - (N - M))
