# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

# Sin mujer no hay llanto

By Riaz_BSMRSTU · Limits 1s, 512 MB

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

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).

## Output

Print the sum of first n elements of this series.

## Sample

InputOutput
```3
1 2
2 2
3 2
```
```1
0
3
```

### Statistics

76% Solution Ratio

Sajjat004Earliest, 2w ago

TurinhstuFastest, 0.0s

Tanim018Lightest, 1.2 MB

mdvirusShortest, 103B

### Related Contests

 BSMRSTU Home Quarantine Contest - 3 Ended 2w ago Replay of BSMRSTU Home Quarantine Contest - 3 Ended 2w ago