Description:

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

More formally, Codeforces 1301 C . Ayoub is equal to the number of pairs of integers Codeforces 1301 C . Ayoub, such that 1≤l≤r≤|s| (where Codeforces 1301 C . Ayoub is equal to the length of string s), such that at least one of the symbols Codeforces 1301 C . Ayoub is equal to Codeforces 1301 C . Ayoub

For example, if Codeforces 1301 C . Ayoub then Codeforces 1301 C . Ayoub because there are Codeforces 1301 C . Ayoub such pairs Codeforces 1301 C . Ayoub

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 Codeforces 1301 C . Ayoub, find the maximum value of Codeforces 1301 C . Ayoub.

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 Codeforces 1301 C . Ayoub

The only line for each test case contains two integers Codeforces 1301 C . Ayoub — the length of the string and the number of symbols equal to Codeforces 1301 C . Ayoub

Output

For every test case print one integer number — the maximum value of Codeforces 1301 C . Ayoub over all strings s of length Codeforces 1301 C . Ayoub, which has exactly m symbols, equal to Codeforces 1301 C . Ayoub.

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 Codeforces 1301 C . Ayoub strings of length Codeforces 1301 C . Ayoub, which has exactly 1 symbol, equal to Codeforces 1301 C . Ayoub. These strings are: Codeforces 1301 C . Ayoub The values of f for them are: Codeforces 1301 C . Ayoub, so the maximum value is Codeforces 1301 C . Ayoub and the answer is Codeforces 1301 C . Ayoub.

In the second test case, the string s with the maximum value is Codeforces 1301 C . Ayoub

In the third test case, the string Codeforces 1301 C . Ayoub with the maximum value is Codeforces 1301 C . Ayoub

In the fourth test case, the only string s of length 4, which has exactly Codeforces 1301 C . Ayoub symbols, equal to Codeforces 1301 C . Ayoub is Codeforces 1301 C . Ayoub and the value of f for that string is Codeforces 1301 C . Ayoub, so the answer is Codeforces 1301 C . Ayoub

In the fifth test case, the string s with the maximum value is Codeforces 1301 C . Ayoub

题意:

给吹一个长度为 Codeforces 1301 C . AyoubCodeforces 1301 C . Ayoub 串,里面有 Codeforces 1301 C . AyoubCodeforces 1301 C . Ayoub ,可以任意选取区间,如果这个区间内至少含有一个 Codeforces 1301 C . Ayoub

我们知道如果都是1的话我们可以选取 Codeforces 1301 C . Ayoub 对,那么如果有连续的 Codeforces 1301 C . Ayoub 那么假设 Codeforces 1301 C . Ayoub 的长度为 Codeforces 1301 C . Ayoub 那不能选取的对数就是 Codeforces 1301 C . Ayoub 。将这些 Codeforces 1301 C . Ayoub 划分为 Codeforces 1301 C . Ayoub 个组,以便使每个组的 Codeforces 1301 C . Ayoub

最优的方法是将它们分成相等的组或尽可能相等。

每组的长度就是 Codeforces 1301 C . Ayoub ,令 Codeforces 1301 C . Ayoub

这些不能选取的区间总数就是 Codeforces 1301 C . Ayoub

如果不能整除划分区间,就把多余的 Codeforces 1301 C . Ayoub 分到每个区间内,这样加上这些 Codeforces 1301 C . Ayoub 对每个区间 不能选取的对数就变成了 Codeforces 1301 C . Ayoub 。全部的就是 Codeforces 1301 C . Ayoub

用全部可选的减去不能选取的就是最后答案。

AC代码:

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
int ret = 0, sgn = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
sgn = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
ret = ret * 10 + ch - '0';
ch = getchar();
}
return ret * sgn;
}
inline void Out(int a) //Êä³öÍâ¹Ò
{
if (a > 9)
Out(a / 10);
putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll a, ll b, ll mod)
{
if (a >= mod)
a = a % mod + mod;
ll ans = 1;
while (b)
{
if (b & 1)
{
ans = ans * a;
if (ans >= mod)
ans = ans % mod + mod;
}
a *= a;
if (a >= mod)
a = a % mod + mod;
b >>= 1;
}
return ans;
}

// 快速幂求逆元
int Fermat(int a, int p) //费马求a关于b的逆元
{
return qpow(a, p - 2, p);
}

///扩展欧几里得
int exgcd(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int g = exgcd(b, a % b, x, y);
int t = x;
x = y;
y = t - a / b * y;
return g;
}

///使用ecgcd求a的逆元x
int mod_reverse(int a, int p)
{
int d, x, y;
d = exgcd(a, p, x, y);
if (d == 1)
return (x % p + p) % p;
else
return -1;
}

///中国剩余定理模板0
ll china(int a[], int b[], int n) //a[]为除数,b[]为余数
{
int M = 1, y, x = 0;
for (int i = 0; i < n; ++i) //算出它们累乘的结果
M *= a[i];
for (int i = 0; i < n; ++i)
{
int w = M / a[i];
int tx = 0;
int t = exgcd(w, a[i], tx, y); //计算逆元
x = (x + w * (b[i] / t) * x) % M;
}
return (x + M) % M;
}

ll n, m;
int t;
ll ans, res, tmp, cnt;

int main()
{
sd(t);
while (t--)
{
sldd(n, m);
ans = n * (n + 1) / 2;
ll z = n - m;
ll k = z / (m + 1);
ans -= (m + 1) *k * (k + 1) / 2;
ans -= (z % (m + 1)) * (k + 1);
pld(ans);
}
return 0;
}