import sys
from math import log, ceil

input = sys.stdin.readline


def poss(n, m, mid):
    return m >= (n // mid)


if __name__ == '__main__':
    for _ in range(int(input().strip())):
        n, m = list(map(int, input().strip().split()))
        if m >= n:
            print((n * (n + 1) // 2))
        elif m == 0:
            print(0)
        else:
            x = n // m
            if x == 1:
                if m != n:
                    x += 1
            ans = (((n - x + 1) * (n - x + 2)) // 2)
            for i in range(1, x):
                ans += min(i, n - i + 1) * m
            print(ans)
            # start = 1
            # end = n
            # mid = (start + end) // 2
            # while end >= start:
            #     mid = (start + end) / 2
            #     if end == start:
            #         break
            #     if poss(n, m, mid):
            #         start = mid + 1
            #     else:
            #         end = mid
            # print(mid)
