#include <bits/stdc++.h>
using namespace std;
long long m = 998244353;
long long mod(long long a) { return ((a % m) + m) % m; }
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
long long power(long long x, long long n) {
  if (n == 0) return 1;
  long long ans = mod(power(x, n / 2));
  ans = mul(ans, ans);
  if (n % 2) ans = mul(ans, x);
  return ans;
}
void solve(int n, int m) {
  int z = n - m;
  int g = m + 1;
  int k = z / g;
  int x = z % g;
  int y = g - x;
  long long ans = n * (n + 1) / 2;
  cout << ans - (k * (k + 1) / 2) * y - ((k + 1) * (k + 2) / 2) * x << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    solve(n, m);
  }
  return 0;
}
