#include <bits/stdc++.h>
using namespace std;
long long fact(long long n) {
  if (n == 0) {
    return 1;
  }
  return (n * fact(n - 1)) % 1000000000000000007;
}
long long power(long long x, long long y) {
  long long out = 1;
  while (y > 0) {
    if (y & 1) out = (out * x) % 1000000000000000007;
    y = y >> 1;
    x = (x * x) % 1000000000000000007;
  }
  return out % 1000000000000000007;
}
long long inverse(long long a) { return power(a, 1000000000000000007 - 2); }
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  gcd(b, a % b);
}
long long a[2000000];
void sieve() {
  long long i, j;
  for (i = 2; i < 1000001; i++) {
    if (a[i] == 0) {
      for (j = i * i; j < 1000001; j += i) {
        a[j] = 1;
      }
    }
  }
}
bool compar(const pair<long long, long long> &a,
            const pair<long long, long long> &b) {
  if (a.first == b.first)
    return (a.second < b.second);
  else
    return (a.first < b.first);
}
vector<long long> v1;
void comp() {
  long long i, j, k, m, x, y, n;
  cin >> n >> m;
  long long temp = n - m;
  long long temp2 = temp / (m + 1);
  long long temp1 = temp % (m + 1);
  long long c1 = (m + 1 - temp1);
  long long sub = ((temp2 * (temp2 + 1)) / 2) * c1 +
                  temp1 * ((temp2 + 1) * (temp2 + 2)) / 2;
  long long ans = (n * (n + 1)) / 2 - sub;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  long long i = 0, t;
  long long n;
  cin >> t;
  while (t--) {
    comp();
  }
}
