#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    int l = 0, r = n + 1;
    while (r - l > 1) {
      long long c = (l + r) / 2;
      if (n / c <= m) {
        r = c;
      } else {
        l = c;
      }
    }
    long long ans = 0;
    ans += m * (1 + l) * l / 2;
    ans += (n - r + 1) * (n - r + 2) / 2;
    cout << ans << "\n";
  }
  return 0;
}
