#include <bits/stdc++.h>
using namespace std;
int dr[8] = {-1, 0, +1, 0, -1, -1, +1, +1};
int dc[8] = {0, +1, 0, -1, -1, +1, -1, +1};
int kx[8] = {-1, +1, +1, -1, +2, +2, -2, -2};
int ky[8] = {+2, +2, -2, -2, -1, +1, +1, -1};
const int N = 100005;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long ans = (n * (n + 1)) / 2LL;
    n -= m;
    m++;
    long long x = n / m;
    long long y = n % m;
    long long zero_sub = 0;
    zero_sub = y * (((x + 1) * (x + 2)) / 2LL);
    zero_sub += ((m - y) * ((x * (x + 1)) / 2LL));
    ans -= zero_sub;
    cout << ans << endl;
  }
}
