
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘T’ lines represent the ‘T’ test cases.
One and only line of each test case contains two space-separated integers ‘n’ and ‘q’ where ‘n’ is the size of the matrix and ‘q’ the value we need to find in the matrix.
For each test case, print an integer denoting the number of cells having value 'q' in a separate line.
Don’t print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10^5
1 <= n <= 10^18
2 <= q <= (n+n)
Time Limit: 1 sec
Let's take the matrix
2 3 4
3 4 5
4 5 6
Now we can see till 4 all the numbers are occurring number-1 times. And if we take 4 as the longest diagonal the number on both sides at an equal distance have the same number of time occurrence. So after the biggest diagonal, the occurrence is 2*n+1-q.