#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 998244353;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % 998244353;
    }
    a = (a * a) % 998244353;
    b >>= 1;
  }
  return res;
}
long long fermat_inv(long long y) { return power(y, 998244353 - 2); }
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
void solve() {
  long long n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << "0\n";
    return;
  }
  long long ans = n * (n + 1);
  ans /= 2;
  long long z = n - m;
  long long val = m + 1;
  long long ans0;
  if (z % val != 0) {
    long long k = z / val;
    ans0 = (val - 1) * ((k * (k + 1)) / 2);
    long long left = z - (k * (val - 1));
    left = left * (left + 1);
    left /= 2;
    ans0 += left;
  } else {
    long long k = z / val;
    ans0 = (val) * ((k * (k + 1)) / 2);
  }
  ans -= ans0;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
