import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil,pi,sin,cos,acos,atan
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush,heappop,heapify
from itertools import permutations,combinations
mod = int(1e9)+7

 
ip = lambda : int(stdin.readline())
inp = lambda: map(int,stdin.readline().split())
ips = lambda: stdin. readline().rstrip()
out = lambda x : stdout.write(str(x)+"\n")

t = ip()
for _ in range(t):
    n,m = inp()
    nn = n
    n -= m
    gaps = m+1
    times = n//gaps
    ans = 0
    remain = n%gaps
    big = remain
    small = gaps-remain
    ans = (((times+1)*(times+2))//2)*big
    ans += ((times*(times+1))//2)*small
    total = (nn*(nn+1))//2
    ans = total-ans
    out(ans)

            
    
    
            
            
        
        
        
        
                   
    
    
    
    
        
        
        
    
    

        

        
    
                
        
