#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
  for (Tp current = _begin; current != _end; ++current) {
    std::cout << *current << _delim;
  }
  std::cout << '\n';
}
using ll = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);
ll Get(int x) { return 1LL * x * (x + 1) / 2; }
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int test_cases;
  cin >> test_cases;
  while (test_cases--) {
    int n, m;
    cin >> n >> m;
    if (m == 0) {
      cout << 0 << "\n";
      continue;
    }
    if (m >= n / 2) {
      cout << Get(n) - n + m << "\n";
      continue;
    }
    auto [q, r] = div(n - m, m + 1);
    cout << Get(n) - (r * Get(q + 1) + (m + 1 - r) * Get(q)) << "\n";
  }
  return 0;
}
