def cal(n, m):
    z = n - m
    g = m + 1
    k = z // g
    n = (n*(n+1))//2
    t = (k*(k+1))//2
    ans = n - t - (k + 1)*(z%g)
    return ans


for _ in range(int(input())):
    n, m = map(int, input().split())
    ans = cal(n, m)
    print(ans)