#include <bits/stdc++.h>
using namespace std;
long long t, l, r;
int main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &l, &r);
    if (r == 0)
      printf("0\n");
    else if (r >= l / 2) {
      long long sum = (1 + l) * l / 2;
      printf("%lld\n", sum - l + r);
    } else {
      long long cnt = l - r;
      long long ans = cnt / (r + 1);
      long long num = cnt - ans * (r + 1);
      long long sum1 = (1 + l) * l / 2;
      long long sum2 = num * (ans + 2) * (ans + 1) / 2;
      long long sum3 = (r + 1 - num) * (ans + 1) * ans / 2;
      printf("%lld\n", sum1 - sum2 - sum3);
    }
  }
  return 0;
}
