#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265358979323846;
const long long modo = 1e9 + 7;
const long long inf = 2e14;
const long long ms = (1e5) + 5;
const long long lim = 1e5;
int ar[ms] = {0};
long long help(long long n) {
  long long aa = (n * (n + 1)) / 2;
  return aa;
}
long long check(long long n, long long m, long long kk) {
  if (kk <= 0) return 0;
  long long ans = help(n);
  long long mul = m * kk;
  int fl = 0;
  if (mul > n) {
    fl = 1;
    m--;
  }
  long long tt = help(kk - 1) * m;
  long long res = n - (m * kk);
  ans -= tt;
  if (res) {
    ans -= help(res - fl);
  }
  return ans;
}
long long peil(long long n, long long k) {
  if (n % k) return n / k + 1;
  return n / k;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    if (!m) {
      cout << "0\n";
    } else if (n == m) {
      cout << help(n) << "\n";
    } else {
      long long kk = help(n);
      long long dd = min(m + 1, n - m);
      long long pp = peil(n - m, dd);
      long long dis = n - m;
      long long a = dd * pp - dis;
      long long b = dd - a;
      long long ans = (help(pp - 1) * a) + (help(pp) * b);
      kk -= ans;
      cout << kk << "\n";
    }
  }
  return 0;
}
