#include <bits/stdc++.h>
using namespace std;
long long PRIME = 1000000007;
long long f(long long n) { return n * (n + 1) / 2; }
void solve() {
  long long n, m;
  cin >> n >> m;
  long long ans = n * (n + 1) / 2;
  ans -= ((n - m) % (m + 1)) * f(1 + (n - m) / (m + 1));
  ans -= (m + 1 - (n - m) % (m + 1)) * f((n - m) / (m + 1));
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
  return 0;
}
