#include <bits/stdc++.h>
using namespace std;
long long bs(long long low, long long high, long long val, long long m) {
  long long ans;
  while (low <= high) {
    long long mid = (low + high) / 2;
    long long res = (m + 1) * mid;
    if (res > val) {
      ans = mid;
      high = mid - 1;
    } else if (res == val) {
      ans = mid;
      break;
    } else {
      low = mid + 1;
    }
  }
  return ans;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long val = n - m;
    long long nval = bs(0, 1e9, val, m);
    long long ttl = (n * (n + 1)) / 2;
    long long pre = nval * (m + 1) - val;
    long long aft = m + 1 - pre;
    ttl -= ((nval - 1) * (nval)*pre) / 2;
    ttl -= ((nval + 1) * nval * aft) / 2;
    cout << ttl << endl;
  }
  return 0;
}
