from sys import stdin
input = stdin.readline

from math import ceil 

def answer():

    total = (n * (n + 1))//2

    if((2 * (m + 1)) > n):
        ans = total - (n - m)
        
    else:

        x = (n - 2 * m)

        ans = total - (m + (x * (x + 1))//2)


    return ans


    
for T in range(int(input())):

    n , m = map(int,input().split())


    print(answer())
