import sys
n = int(input())
for _ in range(n):
    n, m = map(int, sys.stdin.readline().split())
    grp = (n-m)//(m+1)
    ans = (n*(n+1))//2  - ((grp*(grp+1))//2)*(m+1) - (grp+1)*((n-m)%(m+1))              
    print(ans)            
