Xrange makes the best polygonal pancakes in PancakeLand. To grow the business, they hired $m$ line cooks to be pancake rotators and flippers.

A regular n-gon has $n$ vertices, $n$ flipping axes, and $n$ rotation points. We define the following:

Flipping Axes 

If $n$ is odd, each flipping axis passes through a single vertex and the midpoint of the opposite side (resulting in $n$ total flipping axes).
If $n$ is even, $\frac{n}{2}$ flipping axes pass through every pair of opposing vertices and $\frac{n}{2}$ flipping axes pass through every pair of opposing sides.
The angle between consecutive axes is $\frac{360}{2n}$  degrees.
A $\boldsymbol{\mbox{k}}$-flipper flips the pancake at axis number $\boldsymbol{\mbox{k}}$.
Rotation Points 

There are $n$ types of rotators.
A $\boldsymbol{\mbox{k}}$-rotator rotates the the pancake clockwise by $\frac{\left(360\times k\right)}{n}$ degrees. The types of rotators are $\mbox{0}$-rotator, $\mbox{1}$-rotator, …, $(n-1)$-rotator.

Each pancake passes through a long line of rotators and flippers who change the polygonal pancake's orientation during cooking. Xrange wants to hire one more rotator or flipper to restore the pancake to its initial orientation for plating.

Given $n$ and the sequence of rotators and flippers that the pancake passes through, determine which type of rotator or flipper must be added to the end of the line to restore the pancake to its initial orientation.

Input Format

The first line contains two space-separated integers denoting the respective values of $n$ (the number of vertices in the polygonal pancake) and $m$ (the number of line cooks performing the transformations). 

Each line $\boldsymbol{i}$ of the $m$ subsequent lines describes a line cook in the form of two space-separated integers, $\textit{type}$ and $\boldsymbol{\mbox{k}}$ (respectively). If $\textit{type}=1$, line cook $\boldsymbol{i}$ is a rotator; if $\textit{type}=2$, line cook $\boldsymbol{i}$ is a flipper. The second value, $\boldsymbol{\mbox{k}}$, is the integer by which they flip or rotate the pancake; flippers flip the pancake along axis number $\boldsymbol{\mbox{k}}$, and rotators rotate the pancake by $\frac{360\times k}{n}$ degrees.

Constraints

$3\leq n\leq10^{6}$  
$1\leq m\leq10^6$  
$0\leq k<n$   

Output Format

Print a single line with two space-separated integers denoting the respective values of $\textit{type}$ and $\boldsymbol{\mbox{k}}$ for the rotator or flipper needed at the end of the line in order to restore the pancake to its initial orientation. 

Sample Input 0  

5 5
1 1
1 3
2 2
2 2
1 4

Sample Output 0  

1 2

Explanation 0  

The diagram below demonstrates the sequence of flips and rotations performed on the polygonal pancake as it makes its way down the line:

Once the pancake reaches the end of the line, it needs to be rotated (which is $\textit{type}=1$) by $k=2$ to be restored to its original orientation. Thus, we print 1 2 on a new line. 

Sample Input 1  

6 5
1 2
1 4
2 3
2 2
2 4

Sample Output 1  

2 5

Difficulty: EASY
Tags: Geometry

Starter code:

Solutions:
(n, count) = map(int, input().split())
sgn = 1
rot = 0
for i in range(count):
	(t, k) = map(int, input().split())
	t = 3 - 2 * t
	sgn *= t
	rot = k + t * rot
print((3 - sgn) // 2, -sgn * rot % n)


(n, m) = [int(x) for x in input().split(' ')]
a = 0
o = 1
for _ in range(m):
	(t, k) = [int(x) for x in input().split(' ')]
	if t == 1:
		a = (k + a) % n
	else:
		o = 3 - o
		a = (k - a) % n
if o == 1:
	print(1, (n - a) % n)
else:
	print(2, a)


(n, m) = map(int, input().split())
cook = [map(int, input().split()) for i in range(m)]
pos = [0, 1, 2]

def rot(pos, k):
	return list(map(lambda x: x + k, pos))

def flip(pos, k):
	return list(map(lambda x: k - x, pos))
for (type, k) in cook:
	if type == 1:
		pos = rot(pos, k)
	else:
		pos = flip(pos, k)
if sorted(pos) == pos:
	print(1, -pos[0] % n)
else:
	a = pos[0] % n
	print(2, a)


def readintpair():
	return map(int, input().split())
(n, m) = readintpair()
has_rotation = False
pos = 0
for i in range(m):
	(t, k) = readintpair()
	if t == 1:
		pos += k
	else:
		pos = k - pos
		has_rotation = not has_rotation
pos = pos % n
if has_rotation:
	print(2, pos)
else:
	print(1, n - pos)


(n, m) = [int(x) for x in input().strip().split()]
(position, direction) = (0, 0)
for _ in range(m):
	(type, k) = [int(x) for x in input().strip().split()]
	if type == 1:
		position = (position + k) % n
	if type == 2:
		direction = 1 - direction
		position = (n - position + k) % n
if direction == 0:
	print('%s %s' % (1, n - position))
else:
	print('%s %s' % (2, position))


import sys
io = lambda : tuple((int(i) for i in sys.stdin.readline().split()))
(n, m) = io()
v = 0
up = 0
n <<= 1
flip = lambda i, k: (2 * k - i) % n
for i in range(m):
	(t, k) = io()
	if t == 1:
		v = (v + 2 * k) % n
	else:
		v = flip(v, k)
		up ^= 1
if up:
	print('{} {}'.format(2, v >> 1))
else:
	print('{} {}'.format(1, (n - v) % n >> 1))


(N, M) = [int(X) for X in input().split(' ')]
flipped = False
pos = 0
for _ in range(M):
	(T, K) = [int(X) for X in input().split(' ')]
	if T == 1:
		K *= 2
		pos += K
		pos = pos % (2 * N)
	else:
		flipped = flipped == False
		delta = pos - K
		pos = K - delta
		pos += 4 * N
		pos = pos % (2 * N)
if not flipped:
	print('1 {0}'.format(N - pos // 2))
else:
	print('2 {0}'.format(pos // 2))


(n, m) = map(int, input().split())
V = [1] * n
V[0] = 0
flipped = 0
INDEX0 = 0
for _ in range(m):
	(type, k) = map(int, input().split())
	if type == 2:
		flipped = not flipped
		INDEX0 = n - 1 - INDEX0
	INDEX0 = (INDEX0 + k) % n
if not flipped:
	print(1, n - INDEX0)
else:
	print(2, INDEX0 + 1)


(n, m) = input().strip().split(' ')
(n, m) = (int(n), int(m))
top = 0
flip = False
for i in range(m):
	(t, k) = input().strip().split(' ')
	(t, k) = (int(t), int(k))
	if t == 1:
		if flip:
			top += k
		else:
			top -= k
		top = top % n
	if t == 2:
		if flip:
			top = (-k + top) % n
		else:
			top = (k + top) % n
		flip = not flip
t = 0
k = 0
if flip:
	t = 2
	k = top % n
else:
	t = 1
	k = top % n
print(t, end=' ')
print(k, end=' ')


(n, m) = map(int, input().split())
orient = 0
for _ in range(m):
	(t, k) = map(int, input().split())
	if t == 1:
		orient = (orient + 2 * k) % (2 * n)
	else:
		orient = (k - orient // 2) % n * 2 + (orient + 1) % 2
if orient % 2:
	print(2, orient // 2)
else:
	print(1, n - orient // 2)


[n, m] = [int(i) for i in input().split()]
A_pos = 0
ori = 0
for i in range(m):
	[t, k] = [int(i) for i in input().split()]
	if t == 1:
		A_pos = (A_pos + k) % n
	elif t == 2:
		if ori == 1:
			k_index = (A_pos - k) % n
		else:
			k_index = n - (A_pos - k) % n
		ori ^= 1
		if ori == 0:
			A_pos = n - k_index
		else:
			A_pos = k_index
t = 0
k = 0
if ori == 1:
	t = 2
	k = A_pos
else:
	t = 1
	k = n - A_pos
print('{0} {1}'.format(t, k))


(n, m) = [int(i) for i in input().split()]
pos = 0
count = 0
for _ in range(m):
	(type_2, value) = [int(i) for i in input().split()]
	if type_2 == 1:
		pos = (pos + value) % n
	else:
		pos = (value - pos) % n
		count += 1
if count % 2 == 0:
	if pos != 0:
		print('1 ' + str(n - pos))
	else:
		print('1 0')
else:
	print('2 ' + str(pos))


(n, m) = map(int, input().split())
(angle, flip) = (0, 1)
for _ in range(m):
	(x, y) = map(int, input().split())
	if x == 2:
		angle = (y - angle) % n
		flip *= -1
	else:
		angle = (angle + y) % n
if flip == 1:
	print(1, -angle % n)
else:
	print(2, angle)


def solve(n, L):
	P = list(range(0, n))
	flipped = False
	pos = 0
	for T in L:
		t = T[0]
		k = T[1]
		if t == 1:
			pos = (pos + k) % n
		else:
			flipped = not flipped
			fixpoint = k / 2
			pos = int((pos + 2 * (fixpoint - pos)) % n)
	if not flipped:
		return [1, -pos % n]
	else:
		return [2, pos]
(n, m) = map(int, input().split())
L = []
for i in range(m):
	(t, k) = map(int, input().split())
	L.append((t, k))
X = solve(n, L)
print(' '.join(map(str, X)))


import sys
fin = sys.stdin
fout = sys.stdout
line = [int(c) for c in fin.readline().split()]
n = line[0]
m = line[1]
flipped = False
s_loc = 0
for i in range(m):
	line = [int(c) for c in fin.readline().split()]
	if line[0] == 1:
		s_loc = (s_loc + line[1]) % n
	else:
		flipped = not flipped
		s_loc = (line[1] - s_loc) % n
if flipped:
	fout.write('{0} {1}\n'.format(2, s_loc))
else:
	fout.write('{0} {1}\n'.format(1, n - s_loc))


(n, m) = [int(x) for x in input().split()]
curRot = 0
curInv = 0
for i in range(m):
	(t, k) = [int(x) for x in input().split()]
	if t == 1:
		curRot = (curRot + k) % n
	else:
		curRot = (k - curRot) % n
		if curInv == 0:
			curInv = 1
		else:
			curInv = 0
if curInv == 0:
	print('1 ' + str((n - curRot) % n))
else:
	print('2 ' + str(curRot))


(n, m) = [int(i) for i in input().split()]
(a, x) = (0, 1)
for _ in range(m):
	(t, k) = [int(i) for i in input().split()]
	if t == 1:
		a = (a + k) % n
	elif t == 2:
		a = ((n - a) % n + k) % n
		x *= -1
if x == 1:
	print(1, (n - a) % n)
else:
	print(2, a)


(n, m) = [int(i) for i in input().strip().split()]
alpha = 0
flipped = 0
for j in range(m):
	(l, k) = [int(i) for i in input().strip().split()]
	k1 = -1 if l == 1 else 1
	k2 = 1 if flipped % 2 == 0 else -1
	alpha += k1 * k2 * k
	flipped += l - 1
a = 1 if flipped % 2 == 0 else 2
b = alpha % n
print(a, b)


import sys
(n, m) = map(int, input().split())
flipped = False
rotated = 0
for _ in range(m):
	(t, k) = map(int, input().split())
	if t == 1:
		rotated = (rotated + 2 * k) % (2 * n)
	elif t == 2:
		flipped = not flipped
		rotated = (2 * k - rotated) % (2 * n)
	print(flipped, rotated, file=sys.stderr)
if flipped:
	flip_axis = int(rotated / 2)
	print(2, flip_axis)
else:
	rotation_needed = int(n - rotated / 2)
	print(1, rotation_needed)


(n, m) = [int(i) for i in input().split()]
i = 0
flipped = 0
for cook in range(m):
	(command, arg) = [int(i) for i in input().split()]
	if command == 1:
		i = (i + arg) % n
	elif command == 2:
		i = (arg - i) % n
		flipped = 1 - flipped
if flipped == 0:
	print(1, (n - i) % n)
else:
	print(2, i)


class LineCook(object):

	def __init__(self, n, t, k=None):
		if k == None:
			(t, k) = [int(x) for x in t.split()]
		self.n = n
		self.t = t
		self.k = k

	def __iadd__(self, other):
		newt = 1 if self.t == other.t else 2
		newk = (other.k - self.k if other.t == 2 else self.k + other.k) % self.n
		(self.t, self.k) = (newt, newk)
		return self

	def __neg__(self):
		return LineCook(self.n, self.t, (self.n - self.k if self.t == 1 else self.k) % self.n)

	def __str__(self):
		return '%d %d' % (self.t, self.k)

def solve(n, cooks):
	oneCook = LineCook(n, 1, 0)
	for cook in cooks:
		oneCook += cook
	return -oneCook
(n, m) = [int(x) for x in input().split()]
cooks = [LineCook(n, input()) for i in range(m)]
print(solve(n, cooks))


def rotation(a, k):
	return (a + k) % n

def flip(a, k):
	c = k / 2
	return int(a + 2 * (c - a)) % n
a = 0
parity = 0
(n, m) = map(int, input().split())
for i in range(m):
	data = list(map(int, input().split()))
	if data[0] == 1:
		a = rotation(a, data[1])
	else:
		a = flip(a, data[1])
		parity = 1 - parity
if parity == 0:
	print(1, n - a)
else:
	print(2, a)


debug = False
(n, m) = map(int, input().split())
A_pos = 0
flipped = False
for i in range(m):
	if debug:
		print(A_pos, flipped)
	(cook_type, amount) = map(int, input().split())
	if cook_type == 1:
		A_pos += amount * 2
		A_pos = A_pos % (2 * n)
	elif cook_type == 2:
		flipped = not flipped
		if A_pos == amount:
			continue
		dis1 = A_pos - amount
		dis2 = (2 * n + amount - A_pos) % (2 * n)
		if dis1 < dis2:
			A_pos = amount - dis1
			A_pos = A_pos % (2 * n)
		else:
			A_pos = (amount + dis2) % (n * 2)
		flip_dis = min(A_pos - amount, amount - A_pos)
	else:
		print('something wrong....')
if debug:
	print(A_pos)
if flipped:
	print(2, int(A_pos / 2))
else:
	print(1, int((2 * n - A_pos) / 2) % (2 * n))


def rotate(root, k):
	if flipped:
		if root + k < n:
			return root + k
		else:
			return root + k - n
	elif k > root:
		return root - k + n
	else:
		return root - k

def printResult():
	if flipped:
		print(2, root)
	else:
		print(1, root)
(n, m) = [int(tmp) for tmp in input().split()]
root = 0
flipped = False
for _ in range(m):
	(type, k) = [int(tmp) for tmp in input().split()]
	if type == 1:
		root = rotate(root, k)
	else:
		flipped = not flipped
		root = rotate(root, k)
printResult()


def read_line(string):
	nums = string.split()
	return (int(nums[0]), int(nums[1]))
(n, m) = read_line(input())
flip = 1
rot = 0
for i in range(m):
	(typ, num) = read_line(input())
	if typ == 2:
		flip = 3 - flip
		rot += num - 2 * rot
	else:
		rot += num
		rot %= n
if flip == 1:
	print('1 ' + str(n - 1 - (rot - 1) % n))
else:
	print('2 ' + str(rot))


(n, m) = map(int, input().split())
rot = 0
flip = 0
for i in range(m):
	(type, k) = map(int, input().split())
	flip = (flip + type - 1) % 2
	if type == 1:
		rot = (rot + k) % n
	elif type == 2:
		rot = (k - rot) % n
if flip == 0:
	print(1, (n - rot) % n)
elif flip == 1:
	print(2, rot)


(n, m) = map(int, input().split())
posA = 0
num_flips = 0
for i in range(m):
	(typ, k) = map(int, input().split())
	if typ == 1:
		posA = (posA + k) % n
	else:
		posA = (k - posA) % n
		num_flips += 1
if num_flips % 2 == 1:
	print(2, posA)
else:
	print(1, (n - posA) % n)


(n, m) = list(map(int, input().split()))
zeroPos = 0
flip = False
for i in range(0, m):
	move = list(map(int, input().split()))
	if move[0] == 1:
		zeroPos = (zeroPos + move[1]) % n
	elif move[0] == 2:
		if flip:
			flip = False
		else:
			flip = True
		pos = move[1] / 2
		zeroPos = int(pos - (zeroPos - pos)) % n
if flip:
	print(2, zeroPos)
else:
	print(1, (n - zeroPos) % n)


(n, m) = map(int, input().split())
first_vertex_position = 0
orientation_backwards = False
for i in range(m):
	(type, k) = map(int, input().split())
	if type == 1:
		first_vertex_position += k
		first_vertex_position %= n
	else:
		first_vertex_axis = 2 * first_vertex_position % n
		first_vertex_position += k - first_vertex_axis
		first_vertex_position %= n
		orientation_backwards = not orientation_backwards
if orientation_backwards:
	print(2, first_vertex_position)
elif first_vertex_position > 0:
	print(1, (n - first_vertex_position) % n)
else:
	print(1, 0)


(num_verticies, num_cooks) = [int(a) for a in input().split(' ')]
cooks = [[int(a) for a in input().split(' ')] for i in range(0, num_cooks)]
flipped = False
loc = 0

def rotate(loc, axis):
	return (loc + axis) % num_verticies

def flip(loc, axis):
	loc = num_verticies - loc
	loc = rotate(loc, axis)
	return loc
loc = 0
for cook in cooks:
	if cook[0] == 1:
		loc = rotate(loc, cook[1])
	else:
		loc = flip(loc, cook[1])
		flipped = not flipped
if flipped:
	print(2, loc)
else:
	print(1, num_verticies - loc)


import math

def main():
	[n, m] = [int(elt) for elt in input().split(' ')]
	rot_base_angle = 360 / n
	flip_base_angle = 180 / n
	sum_of_rotations = 0
	sum_of_flips = 0
	while m > 0:
		[t, k] = [int(elt) for elt in input().split(' ')]
		if t == 1:
			sum_of_rotations += k * rot_base_angle
		else:
			sum_of_flips += 1
			flip_angle = (sum_of_rotations - k * flip_base_angle) % 360
			sum_of_rotations -= 2 * flip_angle
		sum_of_rotations = sum_of_rotations % 360
		m -= 1
	if sum_of_flips % 2 == 0:
		rot = (360 - sum_of_rotations) % 360 / rot_base_angle
	else:
		rot = sum_of_rotations % 360 / (2 * flip_base_angle)
	upper = math.ceil(rot)
	lower = math.floor(rot)
	if rot - lower < 0.5:
		print(sum_of_flips % 2 + 1, lower)
	else:
		print(sum_of_flips % 2 + 1, upper)
main()


nm = input().split(' ')
n = int(nm[0])
m = int(nm[1])
rt = 0
p = 0
for ti in range(m):
	tk = input().split(' ')
	t = int(tk[0])
	k = int(tk[1])
	if t == 1:
		p = (p + k) % n
	if t == 2:
		p = (n + k - p) % n
		rt ^= t
if rt != 2:
	print(1, n - p)
else:
	print(rt, p)


def flipper(array, index):
	size = len(array)
	if index % 2 == 0:
		index //= 2
		i = (size + index - 1) % size
		j = (size + index + 1) % size
	else:
		i = index // 2
		j = i + 1
	count = 0
(n, m) = map(int, input().split())
index = 0
flipped = False
for cook in range(m):
	(t, k) = map(int, input().split())
	if t == 1:
		index += k
		index %= n
	elif t == 2:
		flipped = not flipped
		index = (n + k - index) % n
	else:
		raise 'Invalid Input'
if not flipped:
	print(1, (n - index) % n)
else:
	print(2, index)


import time
(n, m) = [int(x) for x in input().split(' ')]
start_time = time.time()
a = list(range(0, n))
o = []
prev_c = 0
prev_b = 0
(c, b) = [int(x) for x in input().split(' ')]
start_time = time.time()
b_prev = b
c_prev = c
flag = 0
t = 0
for _ in range(m - 1):
	(c, b) = [int(x) for x in input().split(' ')]
	if c == 1:
		if c_prev == 1:
			b_prev = (b_prev + b) % n
		if c_prev == 2:
			b_prev = (b + b_prev + n) % n
			c_prev = 2
	if c == 2:
		if c_prev == 2:
			b_prev = (b - b_prev + n) % n
			c_prev = 1
		elif c_prev == 1:
			b_prev = (b - b_prev + n) % n
			c_prev = 2
if c_prev == 1:
	print(c_prev, n - b_prev)
else:
	print(c_prev, b_prev)


(n, m) = map(int, input().split())
(a, f) = (0, 0)
for _ in range(m):
	(t, k) = map(int, input().split())
	if t == 1:
		a = (a + k) % n
	else:
		a = (n - a + k) % n
		f += 1
if f % 2 == 0:
	print(1, n - a)
else:
	print(2, a)


(n, m) = map(int, input().split())
(angle, flip) = (0, 1)
for _ in range(m):
	(x, y) = map(int, input().split())
	if x == 2:
		angle = (y - angle) % n
		flip *= -1
	else:
		angle = (angle + y) % n
if flip == 1:
	print(1, -angle % n)
else:
	print(2, angle)


(n, m) = [int(s) for s in input().split()]
cooks = [[int(s) for s in input().split()] for i in range(m)]
sign = 1
rot = 0
for (t, k) in cooks:
	if t == 1:
		rot = (rot + k) % n
	elif t == 2:
		rot = (k - rot) % n
		sign *= -1
if sign == 1:
	print(1, -rot % n)
elif sign == -1:
	print(2, rot)


(n, m) = [int(x) for x in input().split()]
nodes = [0, 1, 2]
for i in range(m):
	(t, k) = [int(x) for x in input().split()]
	if t == 1:
		for j in range(3):
			nodes[j] = (nodes[j] + k) % n
	if t == 2:
		for j in range(3):
			nodes[j] = (k - nodes[j]) % n
canrotate = True
for j in range(2):
	if (nodes[j] + 1) % n != nodes[j + 1]:
		canrotate = False
		break
if canrotate:
	print('1 {}'.format(n - nodes[0]))
else:
	print('2 {}'.format(nodes[0]))


(n, m) = map(int, input().split())
angle_0 = 0
direction_multiplier = 1
for i in range(m):
	(cook_type, k) = map(int, input().split())
	if cook_type == 2:
		direction_multiplier *= -1
	angle_0 = (angle_0 + direction_multiplier * 2 * k) % (2 * n)
if direction_multiplier == -1:
	print(2, abs(angle_0 // 2 - n))
else:
	print(1, abs(angle_0 // 2 - n))


(n, m) = [int(a) for a in input().split()]
flipped = False
rot = 0
for _ in range(m):
	(t, k) = [int(a) for a in input().split()]
	if t == 1:
		rot = (k + rot) % n
	else:
		rot = (k - rot) % n
		flipped = not flipped
if not flipped:
	print(1, n - rot)
else:
	print(2, rot)


def pancake(effect, amount, flipped, vertex, vertices):
	if effect == 2:
		if flipped == 1:
			flipped = 0
		else:
			flipped = 1
	if flipped == 1:
		amount = -amount
	vertex += amount
	return (vertex % vertices, flipped)
(vertices, cooks) = input().strip().split()
(vertices, cooks) = [int(vertices), int(cooks)]
vertex = 0
flipped = 0
for i in range(cooks):
	(e, a) = input().strip().split()
	(e, a) = [int(e), int(a)]
	(vertex, flipped) = pancake(e, a, flipped, vertex, vertices)
mover = int(vertices - vertex)
print(str(1 + flipped) + ' ' + str(mover))


(n, m) = map(int, input().split())
p = 0
r = 0
for i in range(m):
	(t, k) = map(int, input().split())
	if t == 1:
		p += k
	else:
		p = k - p
		r ^= 1
p %= n
if r:
	print('2 ' + str(p))
else:
	print('1 ' + str(n - p))


(n, m) = tuple(map(int, input().split()))
rotation = 0
flipped = False
for _ in range(m):
	(typ, k) = tuple(map(int, input().split()))
	if typ == 1:
		rotation = (rotation + k) % n
	else:
		rotation = (k - rotation) % n
		flipped = not flipped
if flipped:
	typ = 2
	k = rotation
else:
	typ = 1
	k = (n - rotation) % n
print(typ, k)


(n, m) = [int(x) for x in input().split()]
vector = 0
flipped = False
for _ in range(m):
	(t, k) = [int(x) for x in input().split()]
	if t == 1:
		vector += k
		vector %= n
	else:
		flipped = not flipped
		vector *= 2
		vector = vector + 2 * (k - vector)
		vector //= 2
		vector %= n
if flipped:
	print('2 ' + str(vector))
else:
	print('1 ' + str(n - vector))


class Pancake:

	def __init__(self, n):
		self.vertices = n
		self.flipped = False
		self.position = 0

	def flip(self, k):
		if self.flipped:
			self.position -= 2 * k
		else:
			self.position += 2 * k
		self.flipped = not self.flipped

	def rotate(self, k):
		if self.flipped:
			self.position += 2 * k
		else:
			self.position -= 2 * k

	def solution(self):
		if self.flipped:
			k = self.position % (2 * self.vertices) // 2
			print(2, k)
		else:
			print(1, self.position // 2 % self.vertices)

	def status(self):
		print(self.position, self.position // 2 % self.vertices, self.flipped)

def do_work():
	(vertices, line_cooks) = [int(i) for i in input().split()]
	lc = []
	for _ in range(line_cooks):
		lc.append([int(i) for i in input().split()])
	p = Pancake(vertices)
	for l in lc:
		(ct, k) = l
		if ct == 1:
			p.rotate(k)
		else:
			p.flip(k)
	p.solution()
do_work()


import sys
(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
pos_1 = 0
is_even_flips = True
for a0 in range(m):
	(is_rot, k) = input().strip().split(' ')
	k = int(k)
	is_rot = int(is_rot) == 1
	if not is_rot:
		is_even_flips = not is_even_flips
		pos_1 = k - pos_1
		if pos_1 >= n:
			pos_1 %= n
		elif pos_1 < 0:
			pos_1 += n
	else:
		pos_1 = (pos_1 + k) % n
if is_even_flips:
	print('1 ' + str(-pos_1 % n))
else:
	print('2 ' + str(pos_1))


(n, m) = input().strip().split(' ')
(n, m) = [int(n), int(m)]
pos = 0
f = 0
for _ in range(m):
	(a, b) = input().strip().split(' ')
	(a, b) = [int(a), int(b)]
	if a == 1:
		pos = (pos + b) % n
	else:
		pos = (pos + pos * (n - 2) + b) % n
		f += 1
if f % 2 == 0:
	a = 1
	b = n - pos
else:
	a = 2
	b = pos
print(a, b)


(n, m) = map(int, input().split())
r = 0
f = 0
for i in range(m):
	(t, k) = map(int, input().split())
	if t == 1:
		r = (k + r) % n
	elif t == 2:
		f ^= 1
		r = (k - r) % n
if f:
	print(2, r)
else:
	print(1, -r % n)


(n, m) = map(int, input().split())
frontUp = True
origin = 0
for i in range(m):
	(type, k) = map(int, input().split())
	if type == 2:
		frontUp = not frontUp
	if frontUp:
		origin += n - k
	else:
		origin += k
	origin %= n
if frontUp:
	print(1, origin)
else:
	print(2, origin)


import sys
import math

def read_one():
	return int(input().strip())

def read_two():
	(x, y) = input().strip().split(' ')
	return [int(x), int(y)]

def execute(n, cooks):
	type = 1
	head = 0
	for (t, k) in cooks:
		if t == 1:
			head = (head + k) % n
		else:
			head = (k - head + n) % n
			type = 1 if type == 2 else 2
	if type == 1:
		print(1, (n - head) % n)
	else:
		print(2, head)
(n, m) = read_two()
cooks = [read_two() for _ in range(m)]
execute(n, cooks)


def multiply(n, t1, k1, t2, k2):
	if t1 == t2 == 1:
		return (1, (k1 + k2) % n)
	if t1 == 1 and t2 == 2:
		return (2, (k1 + k2) % n)
	if t1 == 2 and t2 == 1:
		return (2, (k1 - k2) % n)
	if t1 == t2 == 2:
		return (1, (k1 - k2) % n)
(n, m) = map(int, input().split())
(cur_t, cur_k) = (1, 0)
for i in range(m):
	(t, k) = map(int, input().split())
	(cur_t, cur_k) = multiply(n, t, k, cur_t, cur_k)
if cur_t == 1:
	print(1, (n - cur_k) % n)
else:
	print(2, cur_k)


(N, Q) = (int(a) for a in input().split())
k = 0
f = False

def flip(n, k, N):
	return int(n - k) % N

def rotate(n, k, N):
	return (n + k) % N
for q0 in range(Q):
	(n, m) = (int(a) for a in input().split())
	if n == 2:
		k = flip(m, k, N)
		f = not f
	else:
		k = rotate(m, k, N)
if f:
	print('2 {}'.format(k))
else:
	print('1 {}'.format(N - k))


face = True
idxA = 0
[n, m] = input().split()
[n, m] = [int(n), int(m)]
for i in range(m):
	[t, k] = input().split()
	[t, k] = [int(t), int(k)]
	if t == 2:
		face = not face
	if t == 1:
		idxA = (idxA + k) % n
	else:
		idxA = (k - idxA) % n
if face:
	t = 1
	k = (n - idxA) % n
else:
	t = 2
	k = idxA
print(t, k)


(n, m) = map(int, input().split())
a = 0
flip = False
for _ in range(m):
	(op, k) = map(int, input().split())
	if op == 1:
		a = (a + k) % n
	else:
		a = (n + k - a) % n
		flip = not flip
if flip:
	print(2, a)
else:
	print(1, (n - a) % n)


import sys
from time import time
tm = time()
(n, m) = map(int, input().split())
(r, f) = (0, 0)
for _ in range(m):
	(t, k) = map(int, input().split())
	if f == 0:
		if t == 1:
			r += k
		elif t == 2:
			f = 1
			r = n - r
			r += k
	elif f == 1:
		if t == 1:
			r += k
		elif t == 2:
			f = 0
			r = n - r
			r += k
	r %= n
if f == 0:
	k = (n - r) % n
elif f == 1:
	k = (r - n) % n
print(f + 1, k)
print('time elapsed: %s' % (time() - tm,), file=sys.stderr)


(n, m) = map(int, input().split())
(a, x) = (False, 0)
for _ in range(m):
	(t, y) = map(int, input().split())
	b = t == 2
	a ^= b
	x = (n + y + (1 - 2 * b) * x) % n
if not a:
	x = (n - x) % n
t = 2 if a else 1
print('{} {}'.format(t, x))


nm = input().split()
n = int(nm[0])
m = int(nm[1])
rot = 0
c = False
for _ in range(m):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	if a == 1:
		rot = (rot + b) % n
	else:
		rot = (n - rot + b) % n
		c = not c
if not c:
	print(1, (n - rot) % n)
else:
	print(2, rot)


(a, b) = [int(s) for s in input().split()]
p = 0
q = 0
for i in range(b):
	(c, d) = [int(s) for s in input().split()]
	if c == 1:
		q = q + 2 * d
		q = q % (2 * a)
	elif c == 2:
		p = p + 1
		if q <= d:
			q = q + 2 * (d - q)
		elif q > d:
			q = q - 2 * (q - d)
		q = q % (2 * a)
if p % 2 == 0:
	if q == 0:
		print(1, end=' ')
		print(0)
	else:
		print(1, end=' ')
		print(int(a - q // 2))
elif p % 2 == 1:
	print(2, end=' ')
	print(int(q // 2))


import os
import sys
(n, m) = map(int, input().split())
a = 0
flip = False
for _ in range(m):
	(op, k) = map(int, input().split())
	if op == 1:
		a = (a + k) % n
	else:
		a = (n - a + k) % n
		flip = not flip
if flip:
	print(2, a)
else:
	print(1, (n - a) % n)


import math as m
(n, c) = map(int, input().split())
R = 360 / n
F = R / 2
A = 0
B = R
for i in range(c):
	a = []
	a[0:2] = map(int, input().split())
	if a[0] == 1:
		A = A + a[1] * R
		B = B + a[1] * R
		if A >= 360:
			A = A - 360
		if B >= 360:
			B = B - 360
	if a[0] == 2:
		y1 = a[1] * F
		y2 = y1 + 180
		A = 2 * y1 - A + 360
		if A >= 360:
			A = A - 360
		B = 2 * y1 - B + 360
		if B >= 360:
			B = B - 360
if B == 0:
	B = 360
if A < B:
	p = 360
	p1 = (360 - A) / R
	p2 = int(p1) + 0.5
	if p1 >= p2:
		print(1, int(p1) + 1)
	else:
		print(1, int(p1))
else:
	p3 = A / R
	p4 = int(p3) + 0.5
	if p3 >= p4:
		print(2, int(p3) + 1)
	else:
		print(2, int(p3))


(n, m) = map(int, input().split())
n2 = n + n
a = 0
f = False
for _ in range(m):
	(t, k) = map(int, input().split())
	if t == 1:
		a = (a + 2 * k) % n2
	else:
		a = (a - k) % n2
		a = (n2 - a) % n2
		a = (a + k) % n2
		f = not f
if f:
	print(2, a // 2)
else:
	print(1, (n2 - a) % n2 // 2)


(n, m) = map(int, input().split())
a = 0
flip = False
for _ in range(m):
	(op, k) = map(int, input().split())
	if op == 1:
		a = (a + k) % n
	else:
		a = (n - a + k) % n
		flip = not flip
if flip:
	print(2, a)
else:
	print(1, (n - a) % n)


(n, m) = [int(i) for i in input().split()]
i = 0
flipped = 0
for cook in range(m):
	(command, arg) = [int(i) for i in input().split()]
	if command == 1:
		i = (i + arg) % n
	elif command == 2:
		i = (arg - i) % n
		flipped = 1 - flipped
if flipped == 0:
	print(1, (n - i) % n)
else:
	print(2, i)


(n, m) = map(int, input().split())
(clockwise_rotation, is_flipped) = (0, False)
for _ in range(m):
	(op, k) = map(int, input().split())
	if op == 1:
		if is_flipped:
			clockwise_rotation = (clockwise_rotation + k) % n
		else:
			clockwise_rotation = (clockwise_rotation - k) % n
	else:
		if is_flipped:
			clockwise_rotation = (clockwise_rotation - k) % n
		else:
			clockwise_rotation = (clockwise_rotation + k) % n
		is_flipped = not is_flipped
if is_flipped:
	print(f'2 {clockwise_rotation}')
else:
	print(f'1 {clockwise_rotation}')