import sys
import copy
from math import *
input=sys.stdin.readline

def bo(i):
    return ord(i)-ord('a')
t=int(input())
while t>0:
    t-=1
    n,m=map(int,input().split())
    c=0
    if(m==0):
        print(0)
        continue
    p=(n-m)//m
    if p==0:
        p=1
    c+=m*(((p)*(p+1))//2)
    d=n-p
    c+=(d*(d+1))//2
    print(c)