from sys import stdin
input = stdin.readline

from math import ceil 

def answer():

    total = (n * (n + 1))//2
    
    if((2 * (m + 1)) > n):
        ans = total - (n - m)
        
    else:

        space = (n//(m + 1))

        div = (n//(space + 1))
        x = n % (space + 1)

        sub = div * (space * (space + 1)//2) + (x * (x + 1))//2

        ans = total - sub


    return ans


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

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


    print(answer())
