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)$.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'a = int(input())\nt = []\nfor _ in range(a):\n (n,k,x,y) = list(map(int,input().split()))\n l = [(0,0),(n,0),(0,n),(n,n)]\n d = {\n }\n tt = 1\n m = 0\n while(tt):\n  if(x>y):\n   b,c = n,y+n-x\n   d[1] = (b,c)\n   if((b,c) in l):\n    t.append((b,c))\n    m = 1\n    break\n   d[2] = (c,b)\n   if((c,b) in l):\n    t.append((c,b))\n    m =1 \n    break\n   b,c = 0,x-y\n   d[3] = (b,c)\n   if((b,c) in l):\n    t.append((b,c))\n    m = 1\n    break\n   d[0] = (c,b)\n   if((c,b) in l):\n    t.append((c,b))\n    m = 1\n    break\n   tt = 0\n  else:\n   c,b = n,x+n-y\n   d[1] = (b,c)\n   if((b,c) in l):\n    t.append((b,c))\n    m = 1\n    break\n   d[2] = (c,b)\n   if((c,b) in l):\n    t.append((c,b))\n    m =1 \n    break\n   c,b = 0,y-x\n   d[3] = (b,c)\n   if((b,c) in l):\n    t.append((b,c))\n    m = 1\n    break\n   d[0] = (c,b)\n   if((c,b) in l):\n    t.append((c,b))\n    m = 1\n    break\n   tt = 0\n   \n if(m == 0):\n  t.append(d[k%4])\nfor i in t:\n print(*i)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13783