#include <bits/stdc++.h>
using namespace std;
template <typename U, typename V>
void Min(U &a, const V &b) {
  if (a > b) a = b;
}
template <typename U, typename V>
void Max(U &a, const V &b) {
  if (a < b) a = b;
}
template <typename U, typename V>
void add(U &a, const V &b) {
  a = (a + b) % 1000000007;
}
template <typename U>
U gcd(U a, U b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a >= b)
    return gcd(a % b, b);
  else
    return gcd(a, b % a);
}
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 1000000007;
    a = 1LL * a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
int pow(int a, int b, int c) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % c;
    a = 1LL * a * a % c;
    b >>= 1;
  }
  return ans;
}
int main() {
  int T, n, m, K, i, j, k;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    if (m == 0) {
      puts("0");
      continue;
    }
    long long ans = 1LL * n * (n + 1) / 2;
    K = n - m;
    if (K <= m + 1) {
      ans -= K;
    } else {
      int first = K / (m + 1);
      int second = K % (m + 1);
      ans -= 1LL * first * (first + 1) / 2 * (m + 1 - second);
      if (second) {
        first++;
        ans -= 1LL * first * (first + 1) / 2 * second;
      }
    }
    printf("%lld\n", ans);
  }
}
