You are playing a Billiards-like game on an $N \times N$ table, which has its four corners at the points $\{(0, 0), (0, N), (N, 0),$ and $(N, N)\}$. You start from a coordinate $(x,y)$,  $(0 < x < N, 0 <  y < N)$ and shoot the ball at an angle $45^{\circ}$ with the horizontal. On hitting the sides, the ball continues to move with the same velocity and ensuring that the angle of incidence is equal to the angle of reflection with the normal, i.e, it is reflected with zero frictional loss. On hitting either of the four corners, the ball stops there and doesn’t move any further. 
Find the coordinates of the point of collision, when the ball hits the sides for the $K^{th}$ time. If the ball stops before hitting the sides $K$ times, find the coordinates of the corner point where the ball stopped instead.

-----Input:-----
- The first line of the input contains an integer $T$, the number of testcases.
- Each testcase contains a single line of input, which has four space separated integers - $N$, $K$, $x$, $y$, denoting the size of the board, the number of collisions to report the answer for, and the starting coordinates.

-----Output:-----
For each testcase, print the coordinates of the ball when it hits the sides for the $K^{th}$ time, or the coordinates of the corner point if it stopped earlier.

-----Constraints-----
- $1 \leq T \leq 10^5$
- $2 \leq N \leq 10^9$
- $1 \leq K \leq 10^9$

-----Subtasks-----
- $30$ points :  Sum of $K$ over all test cases $\le 10^7$
- $70$ points : Original constraints.

-----Sample Input:-----
2
5 5 4 4
5 2 3 1

-----Sample Output:-----
5 5
3 5

-----Explanation:-----
- Sample Case $1$ : 
We are given a $5$ by $5$ board. We shoot the ball from coordinates $(4,4)$, and we need to find its coordinates after it has collided with sides $5$ times. However, after shooting, the ball goes directly to the corner $(5,5)$, and stops there. So we report the coordinates $(5,5)$.

- Sample Case $2$ : 
We are given a $5$ by $5$ board. We shoot the ball from the coordinates $(3,1)$, and we need to find its coordinates after it has collided with the sides twice. After shooting, it first hits the right side at $(5,3)$, and then the top side at $(3,5)$. So, we report $(3,5)$.

Source: codechef | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
t = int(input())
for i in range(t):
	a = 0
	b = 0
	(N, K, x, y) = map(int, input().split())
	if x == y:
		a = N
		b = N
	elif x > y:
		if K % 4 == 1:
			a = N
			b = y - x + N
		elif K % 4 == 2:
			a = y - x + N
			b = N
		elif K % 4 == 3:
			a = 0
			b = x - y
		else:
			a = x - y
			b = 0
	elif K % 4 == 1:
		a = x - y + N
		b = N
	elif K % 4 == 2:
		a = N
		b = x - y + N
	elif K % 4 == 3:
		a = y - x
		b = 0
	else:
		a = 0
		b = y - x
	print(a, b)


a = int(input())
t = []
for _ in range(a):
	(n, k, x, y) = list(map(int, input().split()))
	l = [(0, 0), (n, 0), (0, n), (n, n)]
	d = {}
	tt = 1
	m = 0
	while tt:
		if x > y:
			(b, c) = (n, y + n - x)
			d[1] = (b, c)
			if (b, c) in l:
				t.append((b, c))
				m = 1
				break
			d[2] = (c, b)
			if (c, b) in l:
				t.append((c, b))
				m = 1
				break
			(b, c) = (0, x - y)
			d[3] = (b, c)
			if (b, c) in l:
				t.append((b, c))
				m = 1
				break
			d[0] = (c, b)
			if (c, b) in l:
				t.append((c, b))
				m = 1
				break
			tt = 0
		else:
			(c, b) = (n, x + n - y)
			d[1] = (b, c)
			if (b, c) in l:
				t.append((b, c))
				m = 1
				break
			d[2] = (c, b)
			if (c, b) in l:
				t.append((c, b))
				m = 1
				break
			(c, b) = (0, y - x)
			d[3] = (b, c)
			if (b, c) in l:
				t.append((b, c))
				m = 1
				break
			d[0] = (c, b)
			if (c, b) in l:
				t.append((c, b))
				m = 1
				break
			tt = 0
	if m == 0:
		t.append(d[k % 4])
for i in t:
	print(*i)


n = int(input())
i = 1
while i <= n:
	(N, K, x, y) = input().split()
	N = int(N)
	K = int(K)
	x = int(x)
	y = int(y)
	if x > y:
		if K % 4 == 1:
			print(N, N - x + y)
		elif K % 4 == 2:
			print(N - x + y, N)
		elif K % 4 == 3:
			print(0, x - y)
		else:
			print(x - y, 0)
	elif x == y:
		print(N, N)
	elif K % 4 == 2:
		print(N, N - y + x)
	elif K % 4 == 1:
		print(N - y + x, N)
	elif K % 4 == 0:
		print(0, y - x)
	else:
		print(y - x, 0)
	i = i + 1


for _ in range(int(input())):
	(n, k, x, y) = list(map(int, input().split()))
	if x == y:
		print(n, n)
	else:
		k = (k - 1) % 4 + 1
		if y > x:
			(x, y) = (y, x)
			if k == 1:
				print(y + n - x, n)
			elif k == 2:
				print(n, y + n - x)
			elif k == 3:
				print(x - y, 0)
			else:
				print(0, x - y)
		elif k == 1:
			print(n, y + n - x)
		elif k == 2:
			print(y + n - x, n)
		elif k == 3:
			print(0, x - y)
		else:
			print(x - y, 0)


def res(x, y, n, k):
	d = abs(x - y)
	if x == y:
		print(n, n)
	elif x > y:
		p = k % 4
		if p == 0:
			print(d, 0)
		elif p == 1:
			print(n, n - d)
		elif p == 2:
			print(n - d, n)
		else:
			print(0, d)
	elif x < y:
		p = k % 4
		if p == 0:
			print(0, d)
		elif p == 1:
			print(n - d, n)
		elif p == 2:
			print(n, n - d)
		else:
			print(d, 0)
n = int(input())
for i in range(n):
	(n, k, x, y) = list(map(int, input().split()))
	res(x, y, n, k)


def res(x, y, n, k):
	d = abs(x - y)
	if x == y:
		return (n, n)
	elif x > y:
		if k % 4 == 0:
			return (d, 0)
		if k % 4 == 1:
			return (n, n - d)
		if k % 4 == 2:
			return (n - d, n)
		if k % 4 == 3:
			return (0, d)
	elif x < y:
		if k % 4 == 0:
			return (0, d)
		if k % 4 == 1:
			return (n - d, n)
		if k % 4 == 2:
			return (n, n - d)
		if k % 4 == 3:
			return (d, 0)
n = int(input())
for i in range(n):
	(n, k, x, y) = list(map(int, input().split()))
	(a, b) = res(x, y, n, k)
	print(a, b)


def solve(N, x, y, k):
	if x == y:
		return (N, N)
	elif x > y:
		y += N - x
		x = N
		if k % 4 == 1:
			return (x, y)
		x = y
		y = N
		if k % 4 == 2:
			return (x, y)
		y -= x
		x = 0
		if k % 4 == 3:
			return (x, y)
		return (x + y, 0)
	else:
		x += N - y
		y = N
		if k % 4 == 1:
			return (x, y)
		y = x
		x = N
		if k % 4 == 2:
			return (x, y)
		x -= y
		y = 0
		if k % 4 == 3:
			return (x, y)
		return (0, x + y)
for i in range(int(input())):
	(N, K, x, y) = map(int, input().split())
	print(*solve(N, x, y, K))


import sys
import math

def test_case():
	(N, K, x, y) = [int(i) for i in input().split()]
	dir_x = 1
	dir_y = 1
	if K > 0:
		K %= 4
		if K == 0:
			K = 4
	while K > 0:
		K -= 1
		dis_x = (N - x * dir_x) % N
		dis_y = (N - y * dir_y) % N
		if dis_x == 0:
			dis_x = N
		if dis_y == 0:
			dis_y = N
		if dis_x == dis_y:
			K = 0
		dis = min(dis_x, dis_y)
		x += dis * dir_x
		y += dis * dir_y
		if dis_x < dis_y:
			dir_x *= -1
		else:
			dir_y *= -1
	print(x, y)
T = int(input())
for _ in range(0, T):
	test_case()


try:
	T = int(input())
	for i in range(T):
		(N, K, x, y) = map(int, input().split())
		c = 0
		a = K % 4
		if a == 0:
			a = 4
		if x > y:
			c = 1
		l = [0, N]
		for j in range(a):
			if c == 1:
				if x in l and y in l:
					break
				elif x == N or x == 0:
					(x, y) = (y, x)
				elif y == N or y == 0:
					b = y
					y = N - x
					x = N - b
				else:
					b = N - x
					x += b
					y += b
			elif x in l and y in l:
				break
			elif y == N or y == 0:
				(x, y) = (y, x)
			elif x == N or x == 0:
				b = x
				x = N - y
				y = N - b
			else:
				b = N - y
				x += b
				y += b
		print(x, y)
except EOFError:
	pass


for _ in range(int(input())):
	(n, k, x, y) = list(map(int, input().strip().split()))
	direc = 'upright'
	for i in range(k):
		if direc == 'upright':
			if y > x:
				x += n - y
				y = n
				direc = 'downright'
			else:
				y += n - x
				x = n
				direc = 'upleft'
		elif direc == 'downleft':
			if y > x:
				y -= x
				x = 0
				direc = 'downright'
			else:
				x -= y
				y = 0
				direc = 'upleft'
		elif direc == 'upleft':
			if x + y < n:
				y += x
				x = 0
				direc = 'upright'
			else:
				x -= n - y
				y = n
				direc = 'downleft'
		elif direc == 'downright':
			if x + y < n:
				x += y
				y = 0
				direc = 'upright'
			else:
				y -= n - x
				x = n
				direc = 'downleft'
		if [x, y] in [[0, 0], [0, n], [n, 0], [n, n]]:
			break
	print(x, y)


t = int(input())
for _ in range(t):
	(n, k, x, y) = list(map(int, input().strip().split()))
	if x == y:
		print(n, n)
	else:
		if x < y:
			ans1 = (x + (n - y), n)
			ans2 = (n, x + (n - y))
			ans3 = (y - x, 0)
			ans4 = (0, y - x)
		elif y < x:
			ans1 = (n, y + (n - x))
			ans2 = (y + (n - x), n)
			ans3 = (0, x - y)
			ans4 = (x - y, 0)
		if k % 4 == 1:
			print(ans1[0], ans1[1])
		elif k % 4 == 2:
			print(ans2[0], ans2[1])
		elif k % 4 == 3:
			print(ans3[0], ans3[1])
		else:
			print(ans4[0], ans4[1])


t = int(input())
for a in range(t):
	(n, k, x, y) = map(int, input().split())
	if x == y:
		print(n, n)
	else:
		temp = []
		if x > y:
			temp = [[n, n - x + y], [n - x + y, n], [0, x - y], [x - y, 0]]
		else:
			temp = [[n + x - y, n], [n, n - y + x], [y - x, 0], [0, y - x]]
		ans = temp[(k - 1) % 4]
		print(*ans)


t = int(input())
for _ in range(t):
	(N, K, x, y) = list(map(int, input().split()))
	if x == y:
		print(N, N)
	else:
		temp = []
		if x > y:
			temp = [[N, N - x + y], [N - x + y, N], [0, x - y], [x - y, 0]]
		else:
			temp = [[x + N - y, N], [N, N - y + x], [y - x, 0], [0, y - x]]
		ans = temp[(K - 1) % 4]
		print(*ans)


for _ in range(int(input())):
	(n, k, x, y) = map(int, input().split())
	if x == y:
		print(n, n)
	else:
		l = []
		if x < y:
			l = [[n - y + x, n], [n, n - y + x], [y - x, 0], [0, y - x]]
		else:
			l = [[n, y + n - x], [y + n - x, n], [0, x - y], [x - y, 0]]
		var = l[(k - 1) % 4]
		print(var[0], var[1])