from sys import stdin
input = stdin.readline

from math import ceil 

def answer():

    total = (n * (n + 1))//2

    x = n - m
    div = (x // (m + 1))

    ans = total - (div * (div + 1)//2) * (m + 1) - (div + 1) * (x % (m + 1))


    return ans


    
for T in range(int(input())):

    n , m = map(int,input().split())


    print(answer())
