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 1 is made to the left, and the grasshopper ends up at the point 0 - 1 = -1.

Then, since -1 is an odd number, a jump of length 2 is made to the right, bringing the grasshopper to the point with coordinate -1 + 2 = 1.
9
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1

2
2
2
2
2
2
2
2
2

from os import path, truncate
from sys import int_info, stdin, stdout
if path.exists('tc.txt'):
    stdin = open('tc.txt', 'r')
def gmi(): return map(int, stdin.readline().strip().split())
def gms(): return map(str, stdin.readline().strip().split())
def gari(): return list(map(int, stdin.readline().strip().split()))
def gart(): return tuple(map(int, stdin.readline().strip().split()))
def gars(): return list(map(str, stdin.readline().strip().split()))
def gs(): return stdin.readline().strip()
def gls(): return list(stdin.readline().strip())
def gi(): return int(stdin.readline())

for _ in range(int(input())):
    x,n=map(int,input().split())
    if x%2==0 and (n-1)%4==0:
        print(x-n)
    elif x%2==0 and (n-1)%4==1:
        print(x+1)
    elif x % 2 == 0 and (n-1) % 4 == 2:
        print(x+n+1)
    elif x % 2 == 0 and (n-1) % 4 == 3:
        print(x)
    elif x%2!=0 and (n-1)%4==0:
        print(x+n)
    elif x % 2 != 0 and (n-1) % 4 == 1:
        print(x-1)
    elif x % 2 != 0 and (n-1) % 4 == 2:
        print(x-n-1)
    elif x % 2 != 0 and (n-1) % 4 == 3:
        print(x)





    

   

    

   

# def maxsum(arr):
#     n=len(arr)
#     su=0
#     leftdp=[0]*n
#     rightdp=[0]*n
#     c=0
#     for i in range(0,n,2):
#         su+=arr[i]
#     for i in range(1, n, 2):
#         leftdiff = arr[i]-arr[i-1]
#         if c-1<0:
#             leftdp[i]=leftdiff
#         else:
#             if leftdp[i-2]>0:
#                 leftdp[i]=leftdiff+leftdp[i-2]
#             else:
#                 leftdp[i]=leftdiff
#         rightdiff=0
#         if i+1>=n:
#             rightdiff=0
#         else:
#             rightdiff=arr[i]-arr[i+1]
#         if c-1<0:
#             rightdp[i]=rightdiff
#         else:
#             if rightdp[i-2]>0:
#                 rightdp[i]=rightdiff+rightdp[i-2]
#             else:
#                 rightdp[i]=rightdiff
#         c+=1
#     maxm=0
#     for i  in range(1,n,2):
#          maxm=max(maxm,max(leftdp[i],rightdp[i]))
#     return maxm + su
        
        

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

# x = math.floor(math.log(b)/math.log(2))
# y = math.floor(math.log(a)/math.log(5))
