The nth element of FRUECAK Series can be calculated by following function:
int cal(int n, int d)
{
if(n == 1) return 1;
if(n % 2 == 1)
{
return cal(n - 1, d) + (n - 1) * d;
}
else
{
return cal(n - 1, d) - (n - 1) * d;
}
}
You will be given n and d. You have to calculate sum of first n elements of this series.
Input will contain T (1 ≤ T ≤ 105) Test cases.
Each test case will contain two numbers, n (1 ≤ n ≤ 2×109) and d (1 ≤ d ≤ 10).
Print the sum of first n elements of this series.
Input | Output |
---|---|
3 1 2 2 2 3 2 | 1 0 3 |