from sys import stdin
input = stdin.readline

from math import ceil 

def answer():

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

        x = (n - 2*m)
        sub = m + (x * (x + 1))//2


    return total  - sub


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

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


    print(answer())
