from sys import stdin
input = stdin.readline

from math import ceil 

def answer():

    total = (n * (n + 1))//2
    if(m == 0):return 0
    
    if((2 * (m + 1)) > n):
        ans = total - (n - m)
        
    else:
        x = n % (m + 1)
        sub = ((n//(m + 1)) * (m * (m + 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())
