Given two integers and , determine the first element of the funny array with parameters .
Funny array [a_1, a_2, \dots, a_n] with parameters satisfies the following conditions:
a_{i+1}-a_i=m for all 1 \le i < n.
a_n - a_1 equals the median The median of the array of length is the middle value of the array after sorting it in nondecreasing order. Specifically, the \frac{n + 1}{2}-th element for odd and the \frac{n}{2}-th element for even . For example, if a=[3,1,2], then sorted a=[1,2,3], the median is a_2=2, if a=[4,3,1,2], then sorted a=[1,2,3,4], the median is a_2=2. of the array.
Your task is to find the value of a_1 for given and
The first line contains a single integer (1 \le t \le 10^5) — the number of test cases.
Each test case consists of a single line containing two integers and (1 \le n,m \le 10^9) — the length of the array and its common difference.
For each test case, output a single integer — the value of a_1 for the array a = [a_1,a_2,\ldots,a_n].
It can be proved that there is a unique answer.
Example 1
In the first test case, a valid array is a=[1,2,3], and a_3-a_1=3-1=2.
In the second test case, a valid array is a=[4,8,12], and a_3-a_1=12-4=8.
In the third test case, a valid array is a=[4,6,8,10,12], and a_5-a_1=12-4=8.
Subtask ( points) : (1 \le n,m \le 10)
Subtask ( points) : No additional constraints