import sys
import math as mt
# sys.stdin = open("input.txt","r")
# sys.stdout = open("output.txt","w")
ip = lambda : sys.stdin.readline().rstrip()
ip1 = lambda : map(int,ip().split())
arr = lambda : list(ip1());
inf = float('inf')
def ncr(n,r):
    return (n*(n-1))//2
def f(n,m):
    val=ncr(n,2)+n - (m-1)
    v1=n-2*m+1
    v2=v1-v1//2
    v1//=2
    val-= ncr(v1,2)+ncr(v2,2) +v1+v2
    return val
for _ in range(int(ip())):
    n,m=ip1()
    if m==0:
        print(0)
        continue
    print(f(n,m))
# 001010100 37