#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void dbg(const char* n, Arg1&& arg1) {
  cerr << n << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void dbg(const char* n, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(n + 1, ',');
  cerr.write(n, c - n) << " : " << arg1 << " || ";
  dbg(c + 1, args...);
}
clock_t startTime;
void mainstart();
void mainEnd();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tt = 1;
  scanf("%lld", &tt);
  while (tt--) {
    long long n, m;
    scanf("%lld %lld", &n, &m);
    if (m == 0) {
      printf("0\n");
      continue;
    }
    long long z = n / m - 1;
    if (z == 0) {
      long long ans = n * (n + 1) / 2 - (n - m);
      printf("%lld\n", ans);
      continue;
    }
    long long tim = 5, ans = 0;
    while (tim--) {
      z++;
      long long rem = n - (m + (m - 1) * z);
      if (rem < 0) break;
      dbg("z, rem", z, rem);
      long long a, b;
      a = b = rem / 2;
      if (rem % 2 == 1) b++;
      ans = max(ans, n * (n + 1) / 2 - (m - 1) * (z * (z + 1) / 2) -
                         a * (a + 1) / 2 - b * (b + 1) / 2);
    }
    tim = 10;
    while (tim--) {
      z--;
      if (z < 0) break;
      long long rem = n - (m + (m - 1) * z);
      if (rem < 0) break;
      long long a, b;
      a = b = rem / 2;
      if (rem % 2 == 1) b++;
      ans = max(ans, n * (n + 1) / 2 - (m - 1) * (z * (z + 1) / 2) -
                         a * (a + 1) / 2 - b * (b + 1) / 2);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
void mainstart() { startTime = clock(); }
void mainEnd() {
  clock_t endTime = clock();
  cerr << "Run Time is : " << (float)(endTime - startTime) / CLOCKS_PER_SEC
       << endl;
}
