human
Can you solve the below in PYTHON3?
The grasshopper is located on the numeric axis at the point with coordinate x_0.

Having nothing else to do he starts jumping between integer points on the axis. Making a jump from a point with coordinate x with a distance d to the left moves the grasshopper to a point with a coordinate x - d, while jumping to the right moves him to a point with a coordinate x + d.

The grasshopper is very fond of positive integers, so for each integer i starting with 1 the following holds: exactly i minutes after the start he makes a jump with a distance of exactly i. So, in the first minutes he jumps by 1, then by 2, and so on.

The direction of a jump is determined as follows: if the point where the grasshopper was before the jump has an even coordinate, the grasshopper jumps to the left, otherwise he jumps to the right.

For example, if after 18 consecutive jumps he arrives at the point with a coordinate 7, he will jump by a distance of 19 to the right, since 7 is an odd number, and will end up at a point 7 + 19 = 26. Since 26 is an even number, the next jump the grasshopper will make to the left by a distance of 20, and it will move him to the point 26 - 20 = 6.

Find exactly which point the grasshopper will be at after exactly n jumps.

Input

The first line of input contains an integer t (1 ≤ t ≤ 10^4) — the number of test cases.

Each of the following t lines contains two integers x_0 (-10^{14} ≤ x_0 ≤ 10^{14}) and n (0 ≤ n ≤ 10^{14}) — the coordinate of the grasshopper's initial position and the number of jumps.

Output

Print exactly t lines. On the i-th line print one integer — the answer to the i-th test case — the coordinate of the point the grasshopper will be at after making n jumps from the point x_0.

Example

Input

9
0 1
0 2
10 10
10 99
177 13
10000000000 987654321
-433494437 87178291199
1 0
-1 1

Output

-1
1
11
110
190
9012345679
-87611785637
1
0

Note

The first two test cases in the example correspond to the first two jumps from the point x_0 = 0. 

Since 0 is an even number, the first jump of length...
 ... Write me a Python code to find exactly which point the grasshopper will be at after exactly n jumps?
assistant
#Here is Python code to find exactly which point the grasshopper will be at after exactly n jumps.


#1
# for _ in range(int(input())):
#     k=input()
#     s=input()
#     ans=0
#     dic={}
#     for i,elm in enumerate(k):
#         dic[elm]=i
#     prev=dic[s[0]]
#     for elm in s[1:]:
#         ans+=(abs(dic[elm]-prev))
#         prev=dic[elm]
#     print(ans)

#2
for _ in range(int(input())):
    x,n=map(int,input().split())
    n-=1
    q,r=n//4,n%4
    if x%2==0:
        x-=1
        x-=q*4
    else:
        x+=1
        x+=q*4
    n+=1
    for i in range(n-r+1,n+1):
        if x%2==0:
            x-=i
        else:
            x+=i
    print(x)



















# def solution(arr):
#     n=len(arr)
#     dp=arr[:]
#     for i in range(2,n):
#         if i-3>-1:
#             dp[i]=max(dp[i-3]+dp[i],dp[i],dp[i-2]+dp[i])
#         else:
#             dp[i]=max(dp[i],dp[i-2]+dp[i])
#     return max(dp)
# arr=list(map(int,input().split()))
# print(max(solution(arr[:-1]),solution(arr[1:])))











##group marbles

# def solution(g1,g2,g3):
#     g1=set(g1)
#     g2=set(g2)
#     g3=set(g3)
#     n=len(g1)+len(g2)+len(g3)
#     dp=[[0,0,0] for _ in range(n+1)]
#     dp[1][0]=1 if 1 not in g1 else 0
#     dp[1][1]=1 if 1 not in g2 else 0
#     dp[1][2]=1 if 1 not in g3 else 0

#     for i in range(2,n+1):
#         dp[i][0]+=(1 if i not in g1 else 0)
#         dp[i][0]+=dp[i-1][0]
#         dp[i][1]+=(1 if i not in g2 else 0)
#         dp[i][1]+=min(dp[i-1][0],dp[i-1][1])
#         dp[i][2]+=(1 if i not in g3 else 0)
#         dp[i][2]+=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])

#     print(dp)
#     return min(dp[n])

# g1=list(map(int,input().split()))
# g2=list(map(int,input().split()))
# g3=list(map(int,input().split()))
# print(solution(g1,g2,g3))




# def solution(lb,ub,diff):
#     pre=diff[:]
#     for i in range(1,len(diff)):
#         pre[i]+=pre[i-1]

#     maxi=max(pre)
#     mini=min(pre)
#     if maxi>0:
#         lb=lb+maxi
#     if mini<0:
#         ub=ub-abs(mini)
#     print(pre,lb,ub)
#     return max(ub-lb+1,0)

# arr=list(map(int,input().split()))
#...