#include <bits/stdc++.h>
using namespace std;
long long expo(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b = b >> 1;
  }
  return res;
}
long long mminvprime(long long a, long long b) { return expo(a, b - 2); }
long long add(long long a, long long b) {
  a = a % 1000000007;
  b = b % 1000000007;
  return (((a + b) % 1000000007) + 1000000007) % 1000000007;
}
long long mul(long long a, long long b) {
  a = a % 1000000007;
  b = b % 1000000007;
  return (((a * b) % 1000000007) + 1000000007) % 1000000007;
}
long long sub(long long a, long long b) {
  a = a % 1000000007;
  b = b % 1000000007;
  return (((a - b) % 1000000007) + 1000000007) % 1000000007;
}
long long dv(long long a, long long b) {
  a = a % 1000000007;
  b = b % 1000000007;
  return (mul(a, mminvprime(b, 1000000007)) + 1000000007) % 1000000007;
}
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  t = 1;
  cin >> t;
  for (long long test = 1; test <= t; test++) {
    solve();
  }
  return 0;
}
inline void solve() {
  long long n, k, ans, z, c, r, a, b;
  cin >> n >> k;
  z = n - k;
  if (k == 0) {
    ans = 0;
  } else if (k == n) {
    ans = (n * (n + 1)) / 2;
  } else {
    ans = (n * (n + 1)) / 2;
    c = z / k;
    r = z % k + c;
    c = (k - 1) * ((c * (c + 1)) / 2);
    a = r / 2;
    b = r - a;
    c += (a * (a + 1)) / 2 + (b * (b + 1)) / 2;
    ans = (n * (n + 1)) / 2;
    ans -= c;
  }
  cout << ans << "\n";
}
