------
## 最终结论
```python
def max_f(n, m):
    if m == 0:
        return 0
    zeros = n - m
    full_pairs = (n * (n + 1)) // 2
    zero_pairs = (zeros * (zeros + 1)) // 2
    return full_pairs - zero_pairs

t = int(input())
for _ in range(t):
    n, m = map(int, input().split())
    print(max_f(n, m))
```