#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const long long LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const long long MOD = 1000000007;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = 3.141592653589793;
inline void open(string a) {
  freopen((a + ".in").c_str(), "r", stdin);
  freopen((a + ".out").c_str(), "w", stdout);
}
inline void fasterios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long ceil(long long a, long long b) { return ((a - 1) / b) + 1; }
int main() {
  fasterios();
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long nol = n - m;
    long long satu = m + 1;
    long long a = nol % satu;
    long long awal = nol / satu;
    long long kecil = (awal * (awal + 1)) / 2;
    long long besar = ((awal + 1) * (awal + 2)) / 2;
    long long ans = (a * besar) + (satu - a) * kecil;
    cout << ((n * (n + 1)) / 2) - ans << '\n';
  }
  return 0;
}
