Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

ChefX showed ChefY his new pizza slice design. The design is a planar figure that can be drawn in the following way:
Draw a point $\mathsf{A}_0$ and two rays from this point such that the angle between them is $\alpha < \pi/2$.
Mark $N$ points $\mathsf{A}_1, \mathsf{A}_2, \mathsf{A}_3, \ldots, \mathsf{A}_N$ on one ray in this order ($\mathsf{A}_1$ is closest to $\mathsf{A}_0$).
Mark $N$ points $\mathsf{B}_1, \mathsf{B}_2, \mathsf{B}_3, \ldots, \mathsf{B}_N$ on the other ray in this order ($\mathsf{B}_1$ is closest to $\mathsf{A}_0$).
For each valid $i$, draw a line segment between points $\mathsf{A}_i$ and $\mathsf{B}_{i+1}$.
For each valid $i$, draw a line segment between points $\mathsf{B}_i$ and $\mathsf{A}_{i+1}$.
Finally, draw a line segment between points $\mathsf{A}_N$ and $\mathsf{B}_N$.
All these $2N-1$ line segments must have equal lengths, which must also be equal to $|\mathsf{A}_0\mathsf{A}_1| = |\mathsf{A}_0\mathsf{B}_1|$.

The result should look roughly like this:

ChefY wants to show ChefX that he does not know his own design very well. He asks ChefX to compute the angle between three of the marked points in this figure. It is clear that there are only four types of angles:
1. $\angle \mathsf{A}_x\mathsf{A}_y\mathsf{B}_z$
2. $\angle \mathsf{A}_x\mathsf{B}_y\mathsf{A}_z$
3. $\angle \mathsf{A}_x\mathsf{B}_y\mathsf{B}_z$
4. $\angle \mathsf{B}_x\mathsf{A}_y\mathsf{B}_z$

Can you help ChefX find the angle ChefY asks for? It can be proved that under the given constraints, each angle can be written as $\pi \cdot m / n$, where $m$ and $n$ are coprime integers; you should find $m$ and $n$.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first and only line of each test case contains five space-separated integers $N$, $t$, $x$, $y$ and $z$. Here, $t$ denotes the type of the angle as listed above.

------  Output ------
For each query, print a single line containing two space-separated integers $m$ and $n$.

------  Constraints ------
$1 ≤ T ≤ 10^{5}$
$2 ≤ N ≤ 10^{9}$
$1 ≤ t ≤ 4$
each angle is between three of the points $A_{0}, A_{1}, \ldots, A_{N}, B_{1}, \ldots, B_{N}$
$|x-y| = 1$
$|y-z| = 1$
each angle is non-zero

------  Subtasks ------
Subtask #1 (10 points): $1 ≤ T ≤ 10$

Subtask #2 (90 points): original constraints

----- Sample Input 1 ------ 
1
175456798 1 151163203 151163204 151163205
----- Sample Output 1 ------ 
66583464 116971199
----- explanation 1 ------ 
Example case 1: The type is $1$, so the angle we want is $\mathsf{A}_{151163203}\mathsf{A}_{151163204}\mathsf{B}_{151163205}$. The angle is $(66583464/116971199) \pi \doteq \mathrm{1.7883}$.

Difficulty: HARD

Solutions:
import math
t = int(input())
for i in range(t):
	a = [int(x) for x in input().split()]
	n = a[0]
	op = a[1]
	x = a[2]
	y = a[3]
	z = a[4]
	n1 = n * 2 + 1
	if op == 1:
		if x < y and y < z:
			m = n1 - z
		elif x > y and y > z:
			m = n1 - z
		else:
			m = x
	elif op == 2:
		m = n1 - (z + x)
	elif op == 3:
		if x > y and y > z:
			m = n1 - x
		elif x < y and y < z:
			m = n1 - x
		else:
			m = x
	elif op == 4:
		m = n1 - (z + x)
	gc = math.gcd(m, n1)
	m2 = int(m / gc)
	n2 = int(n1 / gc)
	print(m2, end=' ')
	print(n2)


import math

def solve1(n, x, y, z):
	q = 2 * n + 1
	if (y - x) * (z - y) > 0:
		p = q - z
	else:
		p = x
	return (p, q)

def solve2(n, x, y, z):
	q = 2 * n + 1
	if (y - x) * (z - y) > 0:
		p = q - 2 * y
	else:
		p = 0
	return (p, q)

def solve3(n, x, y, z):
	q = 2 * n + 1
	if y > x and z > y:
		if x == 0:
			p = q
		else:
			p = z + q - 2 * y
	if y > x and z < y:
		p = y - 1
	if y < x and z < y:
		p = q - x
	if y < x and z > y:
		p = z
	return (p, q)

def solve4(n, x, y, z):
	q = 2 * n + 1
	if (y - x) * (z - y) < 0:
		p = 0
	else:
		p = q - x - z
	return (p, q)
T = int(input())
for t in range(0, T):
	(n, t, x, y, z) = map(int, input().split())
	if t == 1:
		(p, q) = solve1(n, x, y, z)
	if t == 2:
		(p, q) = solve2(n, x, y, z)
	if t == 3:
		(p, q) = solve3(n, x, y, z)
	if t == 4:
		(p, q) = solve4(n, x, y, z)
	if int(p):
		print(int(p / math.gcd(p, q)), int(q / math.gcd(p, q)))
	else:
		print(int(p), int(q))


from collections import defaultdict as dd
from collections import Counter as ccd
from itertools import permutations as pp
from itertools import combinations as cc
from random import randint as rd
from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq as hq
from math import gcd
mod = pow(10, 9) + 7

def inp(flag=0):
	if flag == 0:
		return list(map(int, input().strip().split(' ')))
	else:
		return int(input())
t = inp(1)
while t:
	t -= 1
	(n, c, x, y, z) = inp()
	dr = 2 * n + 1
	if c == 1:
		if x < y < z or x > y > z:
			nr = 2 * n + 1 - z
		else:
			nr = x
	elif c == 3:
		if x < y < z or x > y > z:
			nr = 2 * n + 1 - x
		else:
			nr = x
	elif x < y < z or x > y > z:
		nr = 2 * n + 1 - 2 * y
	else:
		nr = 0
	hcf = gcd(nr, dr)
	nr //= hcf
	dr //= hcf
	print(nr, dr)


from math import gcd
t = int(input())
for i in range(t):
	(n, t, x, y, z) = map(int, input().split())
	N = 2 * n + 1
	if t == 1:
		M = 0
		if x > y and y < z:
			M = y + 1
		elif x > y > z:
			M = 2 * n + 2 - y
		elif x < y < z:
			M = 2 * n - y
		elif x < y and y > z:
			M = y - 1
	if t == 3:
		if x > y and y < z:
			M = y + 1
		elif x > y > z:
			M = 2 * n - y
		elif x < y < z:
			M = 2 * n + 2 - y
		elif x < y and y > z:
			M = y - 1
	elif t == 2 or t == 4:
		M = 2 * n - 2 * y + 1
	if gcd(M, N) == 1:
		print(M, N)
	else:
		n1 = N
		m1 = M
		while gcd(M, N) != 1:
			N = N // gcd(m1, n1)
			M = M // gcd(m1, n1)
			n1 = N
			m1 = M
		print(M, N)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
T = int(input())
for i in range(T):
	(N, t, x, y, z) = input().split()
	if t == '1':
		if x != z:
			a = 2 * int(N) + 1 - int(z)
			b = 2 * int(N) + 1
			c = gcd(a, b)
			print(str(int(a / c)) + ' ' + str(int(b / c)))
		else:
			a = int(x)
			b = 2 * int(N) + 1
			c = gcd(a, b)
			print(str(int(a / c)) + ' ' + str(int(b / c)))
	elif t == '2' or t == '4':
		a = 2 * int(N) + 1 - 2 * int(y)
		b = 2 * int(N) + 1
		c = gcd(a, b)
		print(str(int(a / c)) + ' ' + str(int(b / c)))
	elif t == '3':
		if x != z:
			a = 2 * int(N) + 1 - int(x)
			b = 2 * int(N) + 1
			c = gcd(a, b)
			print(str(int(a / c)) + ' ' + str(int(b / c)))
		else:
			a = int(x)
			b = 2 * int(N) + 1
			c = gcd(a, b)
			print(str(int(a / c)) + ' ' + str(int(b / c)))


def ii():
	return int(input())

def spi():
	return input().split()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for spartans in range(int(input())):
	n = list(mi())
	creed = 2 * n[0] + 1
	assasin = 1
	if n[1] == 3:
		if n[2] != n[4]:
			assasin = creed - n[2]
		else:
			assasin = n[2]
		print(assasin // gcd(assasin, creed), creed // gcd(assasin, creed))
		continue
	if n[1] == 1:
		if n[2] == n[4]:
			assasin = n[4]
		else:
			assasin = creed - n[4]
		print(assasin // gcd(assasin, creed), creed // gcd(assasin, creed))
		continue
	else:
		assasin = creed - 2 * n[3]
		print(assasin // gcd(assasin, creed), creed // gcd(assasin, creed))
		continue


def gcd(p, q):
	if p == 0:
		return q
	else:
		return gcd(q % p, p)
num = int(input())
for k in range(num):
	l = list(map(int, input().split()))
	(n, typ, x, y, z) = l
	dnr = 2 * n + 1
	if typ == 1:
		if x != z:
			nmr = dnr - z
		else:
			nmr = z
	elif typ == 2 or typ == 4:
		nmr = dnr - 2 * y
	elif typ == 3:
		if x != z:
			nmr = dnr - x
		else:
			nmr = x
	print(nmr // gcd(nmr, dnr), dnr // gcd(nmr, dnr))


import math
t1 = int(input())
while t1 != 0:
	(n, t, x, y, z) = map(int, input().split())
	a = 0
	b = 0
	n1 = 0
	m = 0
	if t == 1:
		if x < y and x != z:
			a = 2 * n + 1 - z
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
		if x < y and x == z:
			a = x
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
		elif x > y and x != z:
			a = 2 * n + 1 - z
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
		elif x == z:
			a = x
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
	elif t == 2:
		a = 2 * n - 2 * y + 1
		b = 2 * n + 1
		m = a / math.gcd(a, b)
		n1 = b / math.gcd(a, b)
	elif t == 3:
		if x < y and x != z:
			a = 2 * n + 1 - x
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
		elif x < y and x == z:
			a = x
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
		elif x > y and x != z:
			a = 2 * n + 1 - x
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
		elif x == z:
			a = x
			b = 2 * n + 1
			m = a / math.gcd(a, b)
			n1 = b / math.gcd(a, b)
	elif t == 4:
		a = 2 * n - 2 * y + 1
		b = 2 * n + 1
		m = a / math.gcd(a, b)
		n1 = b / math.gcd(a, b)
	print(int(m), int(n1))
	t1 = t1 - 1


from math import *

def theta1(y, lower):
	print((y + 1) // gcd(y + 1, lower), lower // gcd(y + 1, lower))

def theta2(y, lower, n):
	print((2 * n - y + 2) // gcd(2 * n - y + 2, lower), lower // gcd(2 * n - y + 2, lower))

def theta3(y, lower):
	print((y - 1) // gcd(y - 1, lower), lower // gcd(y - 1, lower))

def theta4(y, lower, n):
	print((2 * n - y) // gcd(2 * n - y, lower), lower // gcd(2 * n - y, lower))

def theta5(y, lower, n):
	print((2 * n + 1 - 2 * y) // gcd(2 * n + 1 - 2 * y, lower), lower // gcd(2 * n + 1 - 2 * y, lower))

def theta6(y, lower):
	print(0, lower)

def answer_pizza_question(n, t, x, y, z):
	lower = 2 * n + 1
	if t == 2:
		if z == x:
			theta6(y, lower)
		else:
			theta5(y, lower, n)
	elif t == 3:
		if x > y:
			if z > y:
				theta1(y, lower)
			else:
				theta4(y, lower, n)
		elif x < y:
			if z > y:
				theta2(y, lower, n)
			else:
				theta3(y, lower)
	elif t == 4:
		if x == z:
			theta6(y, lower)
		else:
			theta5(y, lower, n)
	elif t == 1:
		if x > y:
			if z > y:
				theta1(y, lower)
			else:
				theta2(y, lower, n)
		elif z < y:
			theta3(y, lower)
		elif z > y:
			theta4(y, lower, n)
for _ in range(int(input())):
	(n, t, x, y, z) = map(int, input().split())
	answer_pizza_question(n, t, x, y, z)


def gcd(a, b):
	while a % b > 0:
		t = a % b
		a = b
		b = t
	return b

def foo1(a, x, y, z):
	if x > y:
		if y > z:
			return a - z
		else:
			return z
	elif y > z:
		return z
	else:
		return a - z

def foo2(a, x, y, z):
	return a - 2 * y

def foo3(a, x, y, z):
	if x > y:
		if y > z:
			return a - x
		else:
			return x
	elif y > z:
		return x
	else:
		return a - x

def foo4(a, x, y, z):
	return a - 2 * y

def main():
	t = int(input())
	for i in range(t):
		q = [int(q) for q in input().split()]
		a = 2 * q[0] + 1
		b = a
		if q[1] == 1:
			b = foo1(a, q[2], q[3], q[4])
		elif q[1] == 2:
			b = foo2(a, q[2], q[3], q[4])
		elif q[1] == 3:
			b = foo3(a, q[2], q[3], q[4])
		elif q[1] == 4:
			b = foo4(a, q[2], q[3], q[4])
		gcda = gcd(a, b)
		print(f'{b // gcda} {a // gcda}')
main()


import math
test = int(input())
for _ in range(test):
	(n, type, x, y, z) = map(int, input().split())
	alpha = [1, 2 * n + 1]
	ans = [1, 2 * n + 1]
	if y == z:
		print(1, 2 * n + 1)
	else:
		if type == 1:
			if x < y and y < z:
				ans[0] = alpha[1] - z * alpha[0]
			elif x == z and y > x:
				ans[0] = x * alpha[0]
			elif x > y and y > z:
				ans[0] = alpha[1] - z * alpha[0]
			else:
				ans[0] = x * alpha[0]
		elif type == 2 or type == 4:
			ans[0] = alpha[1] - y * 2 * alpha[0]
		elif type == 3:
			if x < y and y < z:
				ans[0] = alpha[1] - x * alpha[0]
			elif x == z and y > x:
				ans[0] = x * alpha[0]
			elif x > y and y > z:
				ans[0] = alpha[1] - x * alpha[0]
			else:
				ans[0] = x * alpha[0]
		temp = math.gcd(ans[0], ans[1])
		ans[0] //= temp
		ans[1] //= temp
		print(ans[0], ans[1])


import math
T = int(input())
for xx in range(T):
	(n, t, x, y, z) = map(int, input().split())
	(a, b) = (0, 0)
	if t == 1:
		if x < y:
			if y < z:
				(a, b) = (2 * n + 1 - z, 2 * n + 1)
			if y > z:
				(a, b) = (z, 2 * n + 1)
		if x > y:
			if y > z:
				(a, b) = (2 * n + 1 - z, 2 * n + 1)
			if y < z:
				(a, b) = (z, 2 * n + 1)
	if t == 2 or t == 4:
		(a, b) = (2 * n + 1 - 2 * y, 2 * n + 1)
	if t == 3:
		if x < y:
			if y < z:
				(a, b) = (2 * n + 1 - x, 2 * n + 1)
			if y > z:
				(a, b) = (x, 2 * n + 1)
		if x > y:
			if y < z:
				(a, b) = (x, 2 * n + 1)
			if y > z:
				(a, b) = (2 * n + 1 - x, 2 * n + 1)
	g = math.gcd(a, b)
	print(a // g, b // g)


import math
t = int(input())
for i in range(t):
	(N, t, x, y, z) = map(int, input().split())
	m = 0
	n = 2 * N + 1
	if t == 1:
		if x == z:
			m = x
		else:
			m = 2 * N + 1 - z
	elif t == 2:
		m = 2 * N + 1 - 2 * y
	elif t == 3:
		if x == z:
			m = x
		else:
			m = 2 * N + 1 - x
	elif t == 4:
		m = 2 * N + 1 - 2 * y
	g_cd = math.gcd(m, n)
	m = m / g_cd
	n = n / g_cd
	print(int(m), int(n))


from math import gcd
from math import pi
z = int(input())
while z:
	(n, t, x, y, z1) = map(int, input().split())
	a = 2 * n + 1
	if t == 1:
		if x < y:
			if x == z1:
				b = x
			else:
				b = a - 1 - y
		elif x == z1:
			b = y + 1
		else:
			b = a - y + 1
	elif t == 2 or t == 4:
		b = a - 2 * y
	elif t == 3:
		if z1 < y:
			if x == z1:
				b = x
			else:
				b = a - 1 - y
		elif x == z1:
			b = y + 1
		else:
			b = a - y + 1
	c = gcd(a, b)
	print(b // c, a // c)
	z = z - 1


from math import gcd

def pri(x, y):
	g = gcd(x, y)
	print(x // g, y // g)
tc = int(input())
for _ in range(tc):
	(n, t, x, y, z) = [int(i) for i in input().split(' ')]
	de = 2 * n + 1
	if t == 1:
		if y == 0:
			pri(1, de)
		elif x < y:
			if x == z:
				pri(y - 1, de)
			elif z == y + 1:
				pri(de - y - 1, de)
		elif x == z:
			pri(y + 1, de)
		elif z == y - 1:
			pri(de - y + 1, de)
	elif t == 2 or t == 4:
		pri(de - 2 * y, de)
	elif t == 3:
		(x, y, z) = (z, y, x)
		if x < y:
			if x == z:
				pri(y - 1, de)
			elif z == y + 1:
				pri(de - y - 1, de)
		elif x == z:
			pri(y + 1, de)
		elif z == y - 1:
			pri(de - y + 1, de)


from math import gcd
for i in range(int(input())):
	(n, t, x, y, z) = map(int, input().split())
	N = n * 2 + 1
	if x + 1 == y and y + 1 == z:
		T = [0, 2 + x, (1 + x) * 2, x, (1 + x) * 2]
	elif x == y + 1 and y == z + 1:
		T = [0, x - 2, 2 * (x - 1), x, 2 * (x - 1)]
	elif x == z and y - 1 == x:
		T = [0, 2 * n + 1 - x, 0, 2 * n + 1 - x, 0]
	else:
		T = [0, 2 * n + 1 - x, 0, 2 * n + 1 - x, 0]
	m = N - T[t]
	g = gcd(N, m)
	print(m // g, N // g)


import math
T = int(input())
for ww in range(T):
	(n, t, x, y, z) = (int(x) for x in input().split())
	M = 0
	N = 2 * n + 1
	if t == 1:
		if x == z:
			M = x
		else:
			M = N - z
	elif t == 2:
		if x == z:
			M = 0
		else:
			M = N - z - x
	elif t == 3:
		if x == z:
			M = x
		else:
			M = N - x
	elif x == z:
		M = 0
	else:
		M = N - z - x
	gcd = math.gcd(M, N)
	print(M // gcd, end=' ')
	print(N // gcd)


from math import gcd
test1 = input()
test = int(test1)
list1 = []
for i in range(test):
	list1.append(list(map(int, input().split())))
for i in range(test):
	n = list1[i][0]
	t = list1[i][1]
	x = list1[i][2]
	y = list1[i][3]
	z = list1[i][4]
	if t == 1 and x > y and (y > z):
		m = int((2 * n + 2 - y) / gcd(2 * n + 2 - y, 2 * n + 1))
		n = int((2 * n + 1) / gcd(2 * n + 2 - y, 2 * n + 1))
		print(m, n)
	elif t == 1 and x > y and (y < z):
		m = int((y + 1) / gcd(y + 1, 2 * n + 1))
		n = int((2 * n + 1) / gcd(y + 1, 2 * n + 1))
		print(m, n)
	elif t == 1 and x < y and (y < z):
		m = int((2 * n - y) / gcd(2 * n - y, 2 * n + 1))
		n = int((2 * n + 1) / gcd(2 * n - y, 2 * n + 1))
		print(m, n)
	elif t == 1 and x < y and (y > z):
		m = int((y - 1) / gcd(y - 1, 2 * n + 1))
		n = int((2 * n + 1) / gcd(y - 1, 2 * n + 1))
		print(m, n)
	elif t == 3 and x > y and (y > z):
		m = int((2 * n - y) / gcd(2 * n - y, 2 * n + 1))
		n = int((2 * n + 1) / gcd(2 * n - y, 2 * n + 1))
		print(m, n)
	elif t == 3 and x > y and (y < z):
		m = int((y + 1) / gcd(y + 1, 2 * n + 1))
		n = int((2 * n + 1) / gcd(y + 1, 2 * n + 1))
		print(m, n)
	elif t == 3 and x < y and (y < z):
		m = int((2 * n + 2 - y) / gcd(2 * n + 2 - y, 2 * n + 1))
		n = int((2 * n + 1) / gcd(2 * n + 2 - y, 2 * n + 1))
		print(m, n)
	elif t == 3 and x < y and (y > z):
		m = int((y - 1) / gcd(y - 1, 2 * n + 1))
		n = int((2 * n + 1) / gcd(y - 1, 2 * n + 1))
		print(m, n)
	elif t == 4 or t == 2:
		m = int((2 * n + 1 - 2 * y) / gcd(2 * n + 1 - 2 * y, 2 * n + 1))
		n = int((2 * n + 1) / gcd(2 * n + 1 - 2 * y, 2 * n + 1))
		print(m, n)
	else:
		pass


from fractions import Fraction
from math import gcd
t = int(input())
for i in range(t):
	(n, t, x, y, z) = map(int, input().split())
	ang = 2 * n + 1
	if t == 1:
		if x == z:
			ans = (z, ang)
		else:
			ans = (ang - z, ang)
	elif t == 2:
		ans = (ang - 2 * y, ang)
	elif t == 3:
		if x == z:
			ans = (x, ang)
		else:
			ans = (ang - x, ang)
	elif t == 4:
		ans = (ang - 2 * y, ang)
	pk = gcd(ans[0], ans[1])
	print(ans[0] // pk, ans[1] // pk)


import math

def gcd(e, r):
	if e > r:
		(e, r) = (r, e)
	while r % e != 0:
		(r, e) = (e, r % e)
	return e

def w(f, p):
	yt = gcd(f, p)
	f = f // yt
	p = p // yt
	print(f, p)
qw = int(input())
for wq in range(qw):
	(n, t, a, b, c) = map(int, input().split())
	d = 2 * n + 1
	nj = 0
	if c < b:
		nj = 1
	if (t == 1 or t == 3) and a == c:
		w(a, d)
	elif a == 0 and b == 1 and (c == 2):
		if t != 3:
			w(d - 2, d)
		else:
			print(1, 1)
	elif t == 2 or t == 4:
		p = d - 2
		f = p - 2 * (b - 1)
		w(f, d)
	elif t == 1:
		if nj == 1:
			f = d - (b - 1)
		else:
			p = d - 2
			f = p - (b - 1)
		w(f, d)
	elif t == 3:
		if nj == 0:
			f = d - (b - 1)
		else:
			f = d - (b + 1)
		w(f, d)


from fractions import Fraction

def zeroPad(n, zeros, left=True):
	for i in range(zeros):
		if left:
			n = '0' + n
		else:
			n = n + '0'
	return n

def func(x, y):
	x = str(x)
	y = str(y)
	if len(x) == 1 and len(y) == 1:
		return int(x) * int(y)
	if len(x) < len(y):
		x = zeroPad(x, len(y) - len(x))
	elif len(y) < len(x):
		y = zeroPad(y, len(x) - len(y))
	n = len(x)
	j = n // 2
	if n % 2 != 0:
		j += 1
	BZeroPadding = n - j
	AZeroPadding = BZeroPadding * 2
	a = int(x[:j])
	b = int(x[j:])
	c = int(y[:j])
	d = int(y[j:])
	ac = func(a, c)
	bd = func(b, d)
	k = func(a + b, c + d)
	A = int(zeroPad(str(ac), AZeroPadding, False))
	B = int(zeroPad(str(k - ac - bd), BZeroPadding, False))
	return A + B + bd
for _ in range(int(input())):
	(a, b, c, d, e) = map(int, input().split())
	y = func(2, 1)
	if c > d > e and c != e:
		if b == y or b == y + 2:
			m = a * 2 + 1 - d * 2
			n = a * 2 + 1
		elif b == y - 1:
			m = a * 2 + 2 - d
			n = a * 2 + 1
		elif b == y + 1:
			m = a * 2 - d
			n = a * 2 + 1
	elif c < d < e and c != e:
		if b == y - 1:
			m = a * 2 - d
			n = a * 2 + 1
		elif b == y or b == y + 2:
			m = a * 2 + 1 - d * 2
			n = a * 2 + 1
		elif b == y + 1:
			m = a * 2 + y - d
			n = a * 2 + 1
	elif c == e:
		if b == y - 1 or b == y + 1:
			if c < d:
				(m, n) = (d - 1, a * y + 1)
			else:
				(m, n) = (d + 1, a * y + 1)
		elif b == y or b == y + 2:
			(n, m) = (y - 1, y - 2)
	print(Fraction(m, n).numerator, Fraction(m, n).denominator)


from math import gcd
te = int(input())
for j in range(te):
	(n, t, x, y, z) = map(int, input().split())
	alpha1 = 90 * 2
	alpha2 = (n - 1 + 2) * 2 - 1
	if t == 1:
		if y > x and z > y:
			r1 = 180 * alpha2 + ((n - z) * 2 + 1) * alpha1
			w = 180 * 2 * alpha2
		if x > y and y > z:
			r1 = 90 * alpha2 * 2 + alpha1 + 2 * (n - x + 2) * alpha1
			w = 180 * 2 * alpha2
		if x > y and z > y:
			r1 = 90 * alpha2 * 2 + alpha1 - 2 * (n - y) * alpha1
			w = 180 * 2 * alpha2
		if y > x and y > z:
			r1 = 90 * alpha2 * 2 - alpha1 - 2 * (n - x) * alpha1
			w = 180 * 2 * alpha2
	elif t == 2 or t == 4:
		if y > x and z > y:
			r1 = (2 * (n - y) + 1) * alpha1
			w = alpha2 * 180
		if x > y and y > z:
			r1 = (2 * (n - y) + 1) * alpha1
			w = alpha2 * 180
	else:
		if y > x and z > y:
			r1 = 90 * alpha2 * 2 + alpha1 + 2 * (n - x) * alpha1
			w = 180 * 2 * alpha2
		if x > y and y > z:
			r1 = 90 * alpha2 * 2 - alpha1 + 2 * (n - y) * alpha1
			w = 180 * 2 * alpha2
		if x > y and z > y:
			r1 = 90 * alpha2 * 2 + alpha1 - 2 * (n - y) * alpha1
			w = 180 * 2 * alpha2
		if y > x and y > z:
			r1 = 90 * alpha2 * 2 - alpha1 - 2 * (n - x) * alpha1
			w = 180 * 2 * alpha2
	f = gcd(r1, w)
	m = r1 // f
	n = w // f
	print(m, end=' ')
	print(n)


import math

def solve():
	(N1, t1, x1, y1, z1) = input().split()
	N = int(N1)
	t = int(t1)
	x = int(x1)
	y = int(y1)
	z = int(z1)
	s = 2 * (N + 1)
	s = s - 1
	if x == z and (t == 1 or t == 3):
		print(int(x / math.gcd(x, s)), int(s / math.gcd(x, s)))
	elif x - z == 2 or x - z == -2:
		if t == 1 and (x - z == 2 or x - z == -2):
			print(int((s - z) / math.gcd(s - z, s)), int(s / math.gcd(s - z, s)))
		elif t == 3 and (x - z == 2 or x - z == -2):
			print(int((s - x) / math.gcd(s - x, s)), int(s / math.gcd(s - x, s)))
		else:
			mu = x + z
			print(int((s - mu) / math.gcd(s - mu, s)), int(s / math.gcd(s - mu, s)))
me = int(input())
for you in range(me):
	solve()


import math
for _ in range(int(input())):
	(N, t, x, y, z) = list(map(int, input().split()))
	d = 2 * N + 1
	if t == 1:
		if z > y and y > x:
			n = d - z
		elif x == z:
			n = x
		elif x > y and y > z:
			n = d - z
	elif t == 2:
		n = d - 2 * y
	elif t == 3:
		if z > y and y > x:
			n = d - x
		elif x == z:
			n = x
		elif x > y and y > z:
			n = d - x
	elif t == 4:
		n = d - 2 * y
	x = math.gcd(n, d)
	print(n // x, d // x)


import math
for _ in range(int(input())):
	(n, t, x, y, z) = [int(x) for x in input().rstrip().split(' ')]
	io = 2 * n + 1
	num = x
	den = io
	if t == 1:
		if x != z:
			num = io - z
	if t == 2 or t == 4:
		num = io - y - y
	if t == 3:
		if x != z:
			num = io - x
	hcf = math.gcd(num, den)
	num = num // hcf
	den = den // hcf
	print(num, end=' ')
	print(den)


import math
T = int(input())
for _ in range(T):
	(N, t, x, y, z) = map(int, input().split())
	marks = []
	n = 2 * N + 1
	if t % 2 == 1:
		if t == 3:
			(x, z) = (z, x)
		if x == y + 1 and z == y + 1:
			m = y + 1
		elif x == y - 1 and z == y + 1:
			m = 2 * N - y
		elif x == y - 1 and z == y - 1:
			m = y - 1
		elif x == y + 1 and z == y - 1:
			m = 2 * N - y + 2
	elif x == z:
		m = 0
		n = 1
	else:
		m = 2 * N - 2 * y + 1
	if m != 0:
		gcd = math.gcd(m, n)
	else:
		gcd = 1
	print(int(m / gcd), int(n / gcd))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for i in range(int(input())):
	(n, t, x, y, z) = [int(y) for y in input().split()]
	al = 2 * n + 1
	m = 0
	gc = 0
	if t == 1:
		if x < y and y > z:
			m = x
		elif x > y and y < z:
			m = x
		elif x < y and y < z:
			m = al - z
		elif x > y and y > z:
			m = al - z
	elif t == 2 or t == 4:
		m = al - 2 * y
	elif t == 3:
		if x < y and y > z:
			m = x
		elif x > y and y < z:
			m = x
		elif x > y and y > z:
			m = al - x
		elif x < y and y < z:
			m = al - x
	gc = gcd(m, al)
	al = al // gc
	m = m // gc
	print(m, end=' ')
	print(al)


T = int(input())
for i in range(T):
	(N, t, x, y, z) = map(int, input().split())

	def gcd(a, b):
		if b == 0:
			return a
		else:
			return gcd(b, a % b)
	if t == 1:
		if x == z:
			print(int(x / gcd(x, 2 * N + 1)), int((2 * N + 1) / gcd(x, 2 * N + 1)))
		else:
			print(int((2 * N + 1 + x - 2 * y) / gcd(2 * N + 1 + x - 2 * y, 2 * N + 1)), int((2 * N + 1) / gcd(2 * N + 1 + x - 2 * y, 2 * N + 1)))
	if t == 2 or t == 4:
		if y == z or (x == y and y == N):
			print(1, int(2 * N + 1))
		else:
			print(int((2 * N + 1 - 2 * y) / gcd(2 * N + 1 - 2 * y, 2 * N + 1)), int((2 * N + 1) / gcd(2 * N + 1 - 2 * y, 2 * N + 1)))
	if t == 3:
		if x == z:
			print(int(x / gcd(x, 2 * N + 1)), int((2 * N + 1) / gcd(x, 2 * N + 1)))
		elif x == y and x == N:
			print(int(x / gcd(x, 2 * N + 1)), int((2 * N + 1) / gcd(x, 2 * N + 1)))
		else:
			print(int((2 * N + 1 + z - 2 * y) / gcd(2 * N + 1 + z - 2 * y, 2 * N + 1)), int((2 * N + 1) / gcd(2 * N + 1 + z - 2 * y, 2 * N + 1)))
quit()


def determine_type(N, t, x, y, z):
	full = -1
	left = 0
	mid = 1
	right = 2
	left_mid = 3
	right_mid = 4
	if y == 0:
		assert t == 1
		return right
	elif y == 1:
		if x == z == 2:
			return right
		elif x == 0 and z == 2:
			if t == 3:
				return full
			else:
				assert t != 4
				return mid
		elif x == 2 and z == 0:
			assert t == 2
			return mid
	elif y == N:
		assert t == 1 or t == 3
		return left
	else:
		assert 1 < y < N
		if x == z:
			assert t == 1 or t == 3
			if x < y:
				return left
			else:
				assert x > y
				return right
		elif t == 2 or t == 4:
			return mid
		elif x < z:
			if t == 1:
				return left_mid
			else:
				assert t == 3
				return right_mid
		else:
			assert x > z
			if t == 1:
				return right_mid
			else:
				assert t == 3
				return left_mid

def get_frac(N, t, x, y, z):
	theta = 2 * N + 1
	angle_type = determine_type(N, t, x, y, z)
	if angle_type == -1:
		return (1, 1)
	if angle_type == 0:
		return (y - 1, theta)
	if angle_type == 1:
		return (2 * N + 1 - 2 * y, theta)
	if angle_type == 2:
		return (y + 1, theta)
	if angle_type == 3:
		return (2 * N - y, theta)
	if angle_type == 4:
		return (2 * N - y + 2, theta)

def gcd(x, y):
	while y != 0:
		t = y
		y = x % y
		x = t
	return x
T = int(input())
for _ in range(T):
	(N, t, x, y, z) = map(int, input().strip().split())
	(num, dom) = get_frac(N, t, x, y, z)
	fac = gcd(num, dom)
	num = num // fac
	dom = dom // fac
	print('{} {}'.format(num, dom))


import math as m
for _ in range(int(input())):
	(n, t, x, y, z) = map(int, input().split())
	if t % 2 == 1:
		if x == z:
			a = z
		elif t == 1:
			a = 2 * n - z + 1
		else:
			a = 2 * n - x + 1
	else:
		a = 2 * n - 2 * y + 1
	g = m.gcd(a, 2 * n + 1)
	a = int(a / g)
	b = int((2 * n + 1) / g)
	print(a, b)


T = int(input())
from math import gcd
while T:
	T -= 1
	(n, t, x, y, z) = map(int, input().strip().split())
	if t == 1:
		if x != z:
			a = 2 * n - z + 1
			b = n * 2 + 1
			g = gcd(a, b)
			print(a // g, end=' ')
			print(b // g)
		else:
			a = x
			b = 2 * n + 1
			g = gcd(a, b)
			print(a // g, end=' ')
			print(b // g)
	elif t == 2 or t == 4:
		if x != z:
			a = 2 * n - 2 * y + 1
			b = 2 * n + 1
			g = gcd(a, b)
			print(a // g, end=' ')
			print(b // g)
		else:
			a = 0
			b = 1
			print(a, end=' ')
			print(b)
	elif t == 3:
		if x != z:
			a = 2 * n + 1 - x
			b = 2 * n + 1
			g = gcd(a, b)
			print(a // g, end=' ')
			print(b // g)
		else:
			a = x
			b = 2 * n + 1
			g = gcd(a, b)
			print(a // g, end=' ')
			print(b // g)


import math
t = int(input())
for _ in range(t):
	(n, tt, x, y, z) = map(int, input().split())
	val = 2 * n + 1
	if tt == 2 or tt == 4:
		y = val - 2 * y
		gc = math.gcd(y, val)
		y //= gc
		val //= gc
	if tt == 1 or tt == 3:
		if y > x and z < y:
			gc = math.gcd(val, y - 1)
			y = (y - 1) // gc
			val //= gc
		elif y > x and z > y and (tt == 1):
			gc = math.gcd(val - y - 1, val)
			y = (val - y - 1) // gc
			val //= gc
		elif y < x and z > y:
			gc = math.gcd(y + 1, val)
			y = (y + 1) // gc
			val //= gc
		elif y < x and z < y and (tt == 1):
			gc = math.gcd(val - y + 1, val)
			y = (val - y + 1) // gc
			val //= gc
		elif y > x and z > y and (tt == 3):
			gc = math.gcd(val - y + 1, val)
			y = (val - y + 1) // gc
			val //= gc
		elif y < x and z < y and (tt == 3):
			gc = math.gcd(val - y - 1, val)
			y = (val - y - 1) // gc
			val //= gc
	print(y, val)


from fractions import Fraction

def func1(x, y, z, n):
	w = 2 * n + 1
	ans = Fraction(180, w)
	if x < y and y > z:
		ans = ans * (y - 1)
	elif x > y and y < z:
		ans = ans * (y + 1)
	elif x < y and y < z:
		inter = 4 * y * ans
		ans = (360 - inter) / 2 + (y - 1) * ans
	elif x > y and y > z:
		inter = 4 * y * ans
		ans = (360 - inter) / 2 + (y + 1) * ans
	ans = ans / 180
	return [ans.numerator, ans.denominator]

def func2(x, y, z, n):
	w = 2 * n + 1
	ans = Fraction(180, w)
	inter = 4 * y * ans
	ans = (360 - inter) / 2
	ans = ans / 180
	return [ans.numerator, ans.denominator]

def func3(x, y, z, n):
	w = 2 * n + 1
	ans = Fraction(180, w)
	if x < y and y > z:
		ans = (y - 1) * ans
	elif x > y and y < z:
		ans = (y + 1) * ans
	elif x > y and y > z:
		inter = 4 * y * ans
		ans = (360 - inter) / 2 + (y - 1) * ans
	elif x < y and y < z:
		inter = 4 * y * ans
		ans = (360 - inter) / 2 + (y + 1) * ans
	ans = ans / 180
	return [ans.numerator, ans.denominator]
t = int(input())
for _ in range(t):
	(n, t, x, y, z) = map(int, input().split())
	if t == 1:
		print(*func1(x, y, z, n))
	elif t == 2:
		print(*func2(x, y, z, n))
	elif t == 3:
		print(*func3(x, y, z, n))
	else:
		print(*func2(x, y, z, n))


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for _ in range(int(input())):
	(n, t, x, y, z) = map(int, input().split())
	b = 2 * n + 1
	if t == 1:
		if x < y:
			if z > y:
				a = 2 * n + 1 - z
			else:
				a = z
		elif z < y:
			a = 2 * n + 1 - z
		else:
			a = z
	elif t == 2:
		a = 2 * n + 1 - 2 * y
	elif t == 3:
		if x < y:
			if z > y:
				a = 2 * n + 1 - x
			else:
				a = x
		elif z < y:
			a = 2 * n + 1 - x
		else:
			a = x
	else:
		a = 2 * n + 1 - 2 * y
	q = gcd(a, b)
	print(a // q, b // q)


from fractions import Fraction

def findAngle(Type, x, y, z, angle):
	if Type == 1:
		if y == x + 1 and z == y - 1:
			return x * angle
		elif y == x + 1 and z == y + 1:
			return 1 - z * angle
		elif y == x - 1 and z == y + 1:
			return x * angle
		elif y == x - 1 and z == y - 1:
			return 1 - z * angle
	elif Type == 2:
		if y == x + 1 and z == y + 1:
			return 1 - angle * 2 * y
		elif y == x - 1 and z == y - 1:
			return 1 - angle * 2 * y
	elif Type == 3:
		if y == x + 1 and z == y - 1:
			return x * angle
		elif y == x - 1 and z == y + 1:
			return x * angle
		elif y == x + 1 and z == y + 1:
			return 1 - angle * x
		elif y == x - 1 and z == y - 1:
			return 1 - angle * x
	elif Type == 4:
		if y == x + 1 and z == y + 1:
			return 1 - angle * 2 * y
		elif y == x - 1 and z == y - 1:
			return 1 - angle * 2 * y
T = int(input())
for i in range(T):
	(n, t, x, y, z) = list(map(int, input().split(' ')))
	angle = Fraction(1, 2 * n + 1)
	ans = findAngle(t, x, y, z, angle)
	print(ans.numerator, ans.denominator)


from fractions import Fraction
t = int(input())

def prin(fra):
	s = str(fra)
	(n, d) = s.split('/')
	print(n + ' ' + d)
one = Fraction(1, 1)
for _ in range(t):
	(n, t, x, y, z) = map(int, input().split())
	alpha = Fraction(1, 2 * n + 1)
	if t == 1:
		if y == 0 and x == 1 and (z == 1):
			prin(alpha)
		else:
			if y > x and z > y:
				prin(one - (y + 1) * alpha)
			if y < x and z > y:
				prin((y + 1) * alpha)
			if y > x and z < y:
				prin((y - 1) * alpha)
			if y < x and z < y:
				prin(one - (y - 1) * alpha)
	if t == 2 or t == 4:
		if x == 0 and z == 0:
			prin(Fraction(0, 1))
		else:
			prin(one - 2 * (y * alpha))
	if t == 3:
		if x == 0 and y == 1 and (z == 2):
			print('1 1')
		else:
			if y > x and z > y:
				prin(one - (y - 1) * alpha)
			if y < x and z > y:
				prin((y + 1) * alpha)
			if y > x and z < y:
				prin((y - 1) * alpha)
			if y < x and z < y:
				prin(one - (y + 1) * alpha)


from math import gcd
f = lambda x, n: x + 1
g = lambda x, n: 2 * n + 1 - 2 * x
func = [[], [lambda x, n: f(x, n) + g(x, n), lambda x, n: f(x, n), lambda x, n: f(x - 2, n), lambda x, n: f(x - 2, n) + g(x, n)], [lambda x, n: g(x, n), lambda x, n: 0, lambda x, n: 0, lambda x, n: g(x, n)], [lambda x, n: f(x - 2, n) + g(x, n), lambda x, n: f(x, n), lambda x, n: f(x - 2, n), lambda x, n: f(x, n) + g(x, n)], [lambda x, n: g(x, n), lambda x, n: 0, lambda x, n: 0, lambda x, n: g(x, n)]]
for _ in range(int(input())):
	(N, t, x, y, z) = map(int, input().split())
	m = func[t][[[3, 0][x > z], [2, 1][x > y]][x == z]](y, N)
	t = gcd(m, 2 * N + 1)
	print(int(m / t), int((2 * N + 1) / t))