Ayoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols "0" and "1"). The function f(s) is equal to the number of substrings in the string s that contains at least one symbol, that is equal to "1".

More formally, f(s) is equal to the number of pairs of integers (l, r), such that 1 ≤ l ≤ r ≤ |s| (where |s| is equal to the length of string s), such that at least one of the symbols s_l, s_{l+1}, …, s_r is equal to "1". 

For example, if s = "01010" then f(s) = 12, because there are 12 such pairs (l, r): (1, 2), (1, 3), (1, 4), (1, 5), (2, 2), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 4), (4, 5).

Ayoub also thinks that he is smarter than Mahmoud so he gave him two integers n and m and asked him this problem. For all binary strings s of length n which contains exactly m symbols equal to "1", find the maximum value of f(s).

Mahmoud couldn't solve the problem so he asked you for help. Can you help him? 

Input

The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of test cases. The description of the test cases follows.

The only line for each test case contains two integers n, m (1 ≤ n ≤ 10^{9}, 0 ≤ m ≤ n) — the length of the string and the number of symbols equal to "1" in it.

Output

For every test case print one integer number — the maximum value of f(s) over all strings s of length n, which has exactly m symbols, equal to "1".

Example

Input


5
3 1
3 2
3 3
4 0
5 2


Output


4
5
6
0
12

Note

In the first test case, there exists only 3 strings of length 3, which has exactly 1 symbol, equal to "1". These strings are: s_1 = "100", s_2 = "010", s_3 = "001". The values of f for them are: f(s_1) = 3, f(s_2) = 4, f(s_3) = 3, so the maximum value is 4 and the answer is 4.

In the second test case, the string s with the maximum value is "101".

In the third test case, the string s with the maximum value is "111".

In the fourth test case, the only string s of length 4, which has exactly 0 symbols, equal to "1" is "0000" and the value of f for that string is 0, so the answer is 0.

In the fifth test case, the string s with the maximum value is "01010" and it is described as an example in the problem statement.
#include <bits/stdc++.h>
class IO {
  static const int bufSize = 1 << 18;
  char inBuf[bufSize], outBuf[bufSize];
  char *ip1 = inBuf, *ip2 = inBuf;
  int goodReadBit = 0, op1 = -1, op2 = bufSize - 1;
  template <typename T>
  __inline__ __attribute__((always_inline)) void __RI(T& x) {
    int ch = gc(), neg = 1;
    x = 0;
    for (; !(isdigit(ch) || ch == '-' || ch == EOF); ch = gc())
      ;
    if (ch == EOF) {
      goodReadBit = 0;
      return;
    }
    if (ch == '-') neg = -1, ch = gc();
    for (; isdigit(ch); ch = gc()) x = x * 10 + (ch - 48) * neg;
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void __RC(T& x) {
    unsigned char ch;
    while (isspace(ch = gc()))
      ;
    x = ch;
  }
  __inline__ __attribute__((always_inline)) void __RS(std::string& x) {
    char ch;
    x.clear();
    for (ch = gc(); isspace(ch); ch = gc())
      ;
    if (ch == EOF) {
      goodReadBit = 0;
      return;
    }
    for (; !isspace(ch); ch = gc()) x.push_back(ch);
  }

 public:
  __inline__ __attribute__((always_inline)) int gc() {
    return ip1 == ip2 && (ip2 = (ip1 = inBuf) + fread(inBuf, 1, bufSize, stdin),
                          ip1 == ip2)
               ? EOF
               : *ip1++;
  }
  __inline__ __attribute__((always_inline)) void R(char& x) { __RC(x); }
  __inline__ __attribute__((always_inline)) void R(unsigned char& x) {
    __RC(x);
  }
  __inline__ __attribute__((always_inline)) void R(std::string& x) { __RS(x); }
  template <typename T1, typename T2>
  __inline__ __attribute__((always_inline)) void R(std::pair<T1, T2>& x) {
    R(x.first), R(x.second);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void R(std::vector<T>& x) {
    for (auto it = x.begin(); it != x.end(); ++it) R(*it);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) void RA(T* a, int n) {
    for (int i = 0; i < n; ++i) R(a[i]);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) void R(T& x, Args&... args) {
    R(x), R(args...);
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) void RA(T* a, int n, Args... args) {
    for (int i = 0; i < n; ++i) RA(a[i], args...);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void R(T& x) {
    static_assert(std::is_integral<T>::value, "Unsupported types");
    if (std::is_integral<T>::value) __RI(x);
  }

 private:
  char space;
  template <typename T>
  __inline__ __attribute__((always_inline)) void __WI(T x) {
    static char buf[64];
    static int len = -1;
    if (x >= 0) {
      do {
        buf[++len] = x % 10 + 48, x /= 10;
      } while (x);
    } else {
      pc('-');
      do {
        buf[++len] = -(x % 10) + 48, x /= 10;
      } while (x);
    }
    while (len >= 0) {
      pc(buf[len]), --len;
    }
  }

 public:
  __inline__ __attribute__((always_inline)) void pc(const char& x) {
    if (op1 == op2) flush();
    outBuf[++op1] = x;
  }
  __inline__ __attribute__((always_inline)) void flush() {
    fwrite(outBuf, 1, op1 + 1, stdout), op1 = -1;
  }
  __inline__ __attribute__((always_inline)) void W(const char& x) { pc(x); }
  __inline__ __attribute__((always_inline)) void W(const char* x) {
    while (*x != '\0') pc(*(x++));
  }
  __inline__ __attribute__((always_inline)) void W(const std::string& x) {
    W(x.c_str());
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void W(const std::vector<T>& x) {
    for (auto it = x.begin(); it != x.end(); it++) WS(*it);
    WL();
  }
  __inline__ __attribute__((always_inline)) void WL() { W('\n'); }
  template <typename T>
  __inline__ __attribute__((always_inline)) void WL(const T& x) {
    W(x), W('\n');
  }
  __inline__ __attribute__((always_inline)) void WS() { W(' '); }
  template <typename T>
  __inline__ __attribute__((always_inline)) void WS(const T& x) {
    W(x), W(space);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void WA(T* a, int n) {
    for (int i = 0; i < n; i++) WS(a[i]);
    WL();
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) void W(const T& x,
                                                   const Args&... args) {
    W(x), W(space), W(args...);
  }
  template <typename... Args>
  __inline__ __attribute__((always_inline)) void WL(const Args&... args) {
    W(args...), W('\n');
  }
  template <typename T, typename... Args>
  __inline__ __attribute__((always_inline)) void WA(T* a, int n, Args... args) {
    for (int i = 0; i < n; i++) WA(a[i], args...);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) void W(const T& x) {
    static_assert(std::is_integral<T>::value, "Unsupported types");
    if (std::is_integral<T>::value) __WI(x);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& operator>>(T& x) {
    R(x);
    return (*this);
  }
  template <typename T>
  __inline__ __attribute__((always_inline)) IO& operator<<(const T& x) {
    W(x);
    return (*this);
  }
  IO() { space = ' '; }
} io;
namespace Alphagocc {
decltype(std::chrono::high_resolution_clock::now()) tStart;
};
void TimeBegin() {
  Alphagocc::tStart = std::chrono::high_resolution_clock::now();
}
long long TimeEnd() {
  return (std::chrono::high_resolution_clock::now() - Alphagocc::tStart)
      .count();
}
using namespace std;
const int8_t INFC = 0x3f;
const int16_t INFS = 0x3f3f;
const int32_t INF = 0x3f3f3f3f;
const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;
int64_t f(int64_t x) { return x * (x + 1) / 2; }
void solve() {
  int64_t n, m;
  io >> n >> m;
  int64_t t = (n - m) / (m + 1);
  int64_t p = n - m - t * (m + 1);
  io.WL(f(n) - (p * f(t + 1) + (m + 1 - p) * f(t)));
}
int main() {
  int T;
  io >> T;
  while (T--) solve();
  io.flush();
  return 0;
}
