#include <bits/stdc++.h>
using namespace std;
long long dp[501][1101];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long i = -1, j = 1, n, k = 0, x = 0, y = 0, l = 0, r = 1, m = 0;
    cin >> n >> m;
    k = n - m;
    x = k / (m + 1);
    y = k % (m + 1);
    j = (m + 1) * ((x * (x + 1)) / 2);
    j += y * (((x + 2) * (x + 1)) / 2);
    j = (n * (n + 1)) / 2 - j;
    cout << j << '\n';
  }
}
