import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
 
for tc in range(int(input())):
    n,m=map(int,input().split())
    ans=(n*(n+1))//2;z=n-m;g=m+1;k=z//g
    print(ans-(k*(k+1)//2)*g-(k+1)*(z%g))
    