#include <bits/stdc++.h>
int main() {
  int t;
  int n, m;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    long long all = n * (n + 1) / 2;
    int rr = (n - m) / (m + 1);
    int tt = (n - m) % (m + 1);
    all -= tt * (rr + 1) * (rr + 2) / 2;
    all -= (m + 1 - tt) * (rr + 1) * rr / 2;
    printf("%lld\n", all);
  }
  return 0;
}
