#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int M = 22;
const int mod = 1e9 + 7;
void solve1() {
  long long n, m;
  cin >> n >> m;
  long long ans = n * (n + 1) / 2;
  long long x = n - m;
  long long cnt = 0;
  long long res = 0;
  if (!x) res = ans;
  for (long long i = 1, yy = 0; i <= x && yy < 10; i++) {
    if (i * i > x) yy += 1;
    long long xx = min(x / i, m + 1);
    long long y = x - xx * i;
    long long z = 1;
    cnt = ans;
    if (y < i) cnt -= y * (y + 1) / 2, z = 0;
    cnt -= (i + y) * (i + 1 + y) / 2 * z;
    cnt -= i * (i + 1) / 2 * (xx - z);
    res = max(res, cnt);
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int cghf = 1;
  cin >> cghf;
  while (cghf--) {
    solve1();
  }
}
