#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 1000 * 1000 * 1000 + 7;
constexpr int ALPHABET_SIZE = 26;
constexpr ll INF = 1e18;
int main() {
  ios_base::sync_with_stdio(false);
  size_t T;
  cin >> T;
  for (size_t t = 0; t < T; ++t) {
    ull n, m;
    cin >> n >> m;
    ull d = (n - m) / (m + 1);
    ull r = (n - m) % (m + 1);
    ull res = r * (d + 1) * (d + 2) / 2 + (m + 1 - r) * d * (d + 1) / 2;
    cout << n * (n + 1) / 2 - res << "\n";
  }
  return 0;
}
