#include <bits/stdc++.h>
const long double PI = acos(-1);
const long long INF = 9e14;
const long long MOD = 1e9 + 7;
const long long MAXN = 1e5 + 5;
const long double EPS = 1e-3;
using namespace std;
long long n, m, T;
int main() {
  cout.precision(15);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> T;
  for (int t = 0; t < T; ++t) {
    cin >> n >> m;
    if (m == 0) {
      cout << 0 << endl;
      continue;
    }
    ++m;
    long long a = (n + 1) / m - 1;
    long long b = a * (a + 1) / 2;
    cout << (n * (n + 1) / 2) - b * m - (a + 1) * ((n + 1) % m) << endl;
  }
  return 0;
}
