#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
const long long INF = 0x3f3f3f3f3f3f3f3f;
int a[maxn];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, m;
    scanf("%lld %lld", &n, &m);
    long long o = n - m, val = o / (m + 1), les = o % (m + 1);
    long long ans =
        n * (n + 1) / 2 - val * (val + 1) / 2 * (m + 1) - (val + 1) * les;
    printf("%lld\n", ans);
  }
  return 0;
}
