#include <bits/stdc++.h>
using namespace std;
const double PI = 4 * atan(1);
const long long INF = 1e18;
const int MX = 100001;
long long t, m, n;
long long c2(long long n) { return ((n) * (n + 1LL)) / (long long)2; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  for (int cs = 1; cs <= t; cs++) {
    cin >> n >> m;
    long long num_gaps = m + 1;
    long long nmn = n - m;
    long long a1 = nmn / num_gaps;
    long long a2 = nmn - (num_gaps - 1) * a1;
    long long ans = c2(n + 1) - (num_gaps - 1) * c2(a1 + 1) - c2(a2 + 1);
    cout << ans << "\n";
  }
}
