import sys

input = sys.stdin.readline


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


if __name__ == '__main__':
    out = []
    for _ in range(int(input().strip())):
        n, m = list(map(int, input().strip().split()))
        if m >= n:
            out.append((n * (n + 1) // 2))
        elif m == 0:
            out.append(0)
        else:
            start = 1
            end = n
            mid = (start + end) // 2
            while end >= start:
                mid = (start + end) // 2
                if end == start:
                    break
                if poss(n, m, mid):
                    end = mid
                else:
                    start = mid + 1
            ans = (((n - mid + 1) * (n - mid + 2)) // 2)
            if mid <= (n + 1) // 2:
                ans += ((mid * (mid - 1)) // 2) * m
            else:
                pp = (n + 1) // 2
                ans += (pp * (pp + 1)) // 2
                st = n - mid
                en = pp - 1
                ans += (en * (en + 1)) // 2
                ans -= (st * (st + 1)) // 2
            # for i in range(1, mid):
            #     ans += min(i, n - i + 1) * m
            out.append(ans)
    print('\n'.join(map(str, out)))
