#include <bits/stdc++.h>
const int N = 3e5 + 5;
const long double pi = 3.141592653;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
const long long INF = 9223372036854775807LL;
using namespace std;
int dx[9] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 0, 1, -1, 1, -1, 1, -1, 0};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  cin >> T;
  while (T--) {
    long long n, m, k, ans;
    cin >> n >> m;
    if (n == m)
      ans = (n * (n + 1)) / 2;
    else {
      k = (n - m) / (m + 1);
      if (k == 0)
        ans = m + (n * (n - 1)) / 2;
      else
        ans = (m * k * (k + 1)) / 2 + ((n - k) * (n - k + 1)) / 2;
    }
    cout << ans << "\n";
  }
  return 0;
}
