import sys
import bisect
from collections import deque
 
def no():
    print("NO")    
 
def dist(z, c):
    return (z[0] - c[0]) * (z[0] - c[0]) + (z[1] - c[1]) * (z[1] - c[1]);
 
def vec(z, c):
    return z[0] * c[1] - z[1] * c[0]
    
def pro(z,c):
    return [z[0] - c[0], z[1] - c[1]]
 
def main():
    # q = [int(i) for i in sys.stdin.readline().split()]
    n, m = [int(i) for i in sys.stdin.readline().split()]
    print(n * (n + 1) // 2 - (((n - m) % (m + 1)) * ((n - m) // (m + 1) + 1) * ((n - m) // (m + 1) + 2) // 2 + ((m + 1) - (n - m) % (m + 1)) * ((n - m) // (m + 1)) * ((n - m) // (m + 1) + 1) // 2))
for i in range(int(sys.stdin.readline())):
    main()