#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long maxn = 201110;
const long long M = 1e9 + 7;
long long n, m;
signed main() {
  long long T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    long long ans = (n + 1) * n / 2;
    long long a = (n - m) / (m + 1);
    long long b = (n - m) % (m + 1);
    ans = ans - (m + 1 - b) * a * (a + 1) / 2 - b * (a + 2) * (a + 1) / 2;
    cout << ans << endl;
  }
  return 0;
}
