CF2148A.Sublime Sequence

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Sublime Sequence

Farmer John has an integer xx. He creates a sequence of length nn by alternating integers xx and x-x, starting with xx.

For example, if n=5n = 5, the sequence looks like: x,x,x,x,xx, -x, x, -x, x.

He asks you to find the sum of all integers in the sequence.

Input

The first line contains an integer tt (1t1001 \leq t \leq 100)  — the number of test cases.

The only line of input for each test case is two integers xx and nn (1x,n101 \leq x, n \leq 10).

Output

For each test case, output the sum of all integers in the sequence.

Samples

4
1 4
2 5
3 6
4 7
0
2
0
4

在线编程 IDE

建议全屏模式获得最佳体验