import atexit
import io
import sys
import math
from collections import defaultdict,Counter

_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

# sys.stdout=open("CP3/output.txt",'w')
# sys.stdin=open("CP3/input.txt",'r')

# m=pow(10,9)+7
t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    if m==0:
        print(0)
    elif n==m:
        print(n*(n+1)//2)
    else:
        d=n-m
        if m>=n//2:
            print((n*(n+1))//2-d)
        else:
            if n%2==0:
                d1=(n//2)*(n//2+1)
            else:
                d1=(n//2+1)*(n//2+1)
            d1+=(m-1)*4
            print(d1)
