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