#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mk make_pair
using namespace std;
const int N = 1123456;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
inline long long read () {
    char c = getchar();
    long long t = 0, f = 1;
    while (!isdigit(c)) f = (c == '-') ? -1 : 1, c = getchar();
    while (isdigit(c)) t = t * 10 + c - 48, c = getchar();
    return t * f;
}
int a[N];
void solve() {
    int n, m, i, j;
    cin >> n >> m;
    if(m == 0) {
        puts("0");
        return ;
    }
    int t = n - m;
    m ++;
    if(t <= m) {
        cout << (n * (n + 1)) / 2 - t << endl;
    }
    else {
        int y = t / m;
        int ans = y * (y + 1) / 2 * (t % m);
        ans += (y + 2) * (y + 1) / 2 * (m - t % m);
        cout << (n * (n + 1)) / 2 - ans << endl;
    }
}
main()
{
    int t = read();
    while(t -- > 0) {
        solve();
    }
}



