import sys
input=sys.stdin.readline
from math import ceil,floor
t=int(input())
import bisect
while t:
    n,m=map(int,input().split())
    ans=0
    a=min(m,n//2)
    n1=2*a
    if(n1%2):
        nn=n1-2
    else:
        nn=n1-1
    #print(a,nn)
    nt=(nn+1)//2
    #print(nt)
    ans=2*(n*a-(nt*nt))+max(0,m-a)
    print(ans)
    t-=1