from sys import stdin, stdout
def main():
    t = int(stdin.readline())
    a = [map(int, stdin.readline().split()) for _ in xrange(t)]
    ans = []
    for n, m in a:
        p, r = divmod(n - m, m + 1)
        ans.append(n * (n + 1) / 2 - p * (p + 1) / 2 * (m + 1 - r) - (p + 1) * (p + 2) / 2 * r)
    stdout.write('\n'.join(map(str, ans)))
main()
