The Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, whereas in fact, as we now all know, there will never be more than 250.

Heidi recently got her hands on a multiverse observation tool. She was able to see all $n$ universes lined up in a row, with non-existent links between them. She also noticed that the Doctor was in the $k$-th universe.

The tool also points out that due to restrictions originating from the space-time discontinuum, the number of universes will never exceed $m$.

Obviously, the multiverse is unstable because of free will. Each time a decision is made, one of two events will randomly happen: a new parallel universe is created, or a non-existent link is broken.

More specifically,   When a universe is created, it will manifest itself between any two adjacent universes or at one of the ends.   When a link is broken, it could be cut between any two adjacent universes. After separating the multiverse into two segments, the segment NOT containing the Doctor will cease to exist. 

Heidi wants to perform a simulation of $t$ decisions. Each time a decision is made, Heidi wants to know the length of the multiverse (i.e. the number of universes), and the position of the Doctor.


-----Input-----

The first line contains four integers $n$, $k$, $m$ and $t$ ($2 \le k \le n \le m \le 250$, $1 \le t \le 1000$).

Each of the following $t$ lines is in one of the following formats:   "$1$ $i$" — meaning that a universe is inserted at the position $i$ ($1 \le i \le l + 1$), where $l$ denotes the current length of the multiverse.  "$0$ $i$" — meaning that the $i$-th link is broken ($1 \le i \le l - 1$), where $l$ denotes the current length of the multiverse. 


-----Output-----

Output $t$ lines. Each line should contain $l$, the current length of the multiverse and $k$, the current position of the Doctor.

It is guaranteed that the sequence of the steps will be valid, i.e. the multiverse will have length at most $m$ and when the link breaking is performed, there will be at least one universe in the multiverse.


-----Example-----
Input
5 2 10 4
0 1
1 1
0 4
1 2

Output
4 1
5 2
4 2
5 3



-----Note-----

The multiverse initially consisted of 5 universes, with the Doctor being in the second.

First, link 1 was broken, leaving the multiverse with 4 universes, and the Doctor in the first.

Then, a universe was added to the leftmost end of the multiverse, increasing the multiverse length to 5, and the Doctor was then in the second universe.

Then, the rightmost link was broken.

Finally, a universe was added between the first and the second universe.

Difficulty: interview

Starter code:

Solutions:
n,k,m,t=list(map(int,input().split()))
for i in range(t):
    a,b=list(map(int,input().split()))
    if a==1:
        if b<=k:
            k+=1
        n+=1
        print(n,k)
    else :
        if k>b:
            n=n-b
            k=k-b
        else :
            n=b
        print(n,k)


n, k, m, t = map(int, input().split())
l = n
for i in range(t):
	a, b = map(int, input().split())
	if(a==0):
		if(b<k):
			l = l-b
			k = k-b
		else:
			l = b
	else:
		l+=1
		if(b<=k):
			k+=1
	print(l,k)

# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor
from copy import deepcopy
from itertools import accumulate
from collections import Counter
import math
from functools import reduce
from bisect import bisect_right
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(x): print("debug: ", x, file=sys.stderr)
# template


def main():
    n, k, m, t = mi()
    ans = [k - 1, n - k]
    # print(ans)
    for i in range(t):
        c, i = mi()
        if c == 1:
            if i <= ans[0]+1:
                ans[0] += 1
            else:
                ans[1] += 1
        else:
            if i <= ans[0]:
                ans[0] -= i
            else:
                ans[1] = i - ans[0] - 1
        print(sum(ans)+1, ans[0]+1)


def __starting_point():
    main()

__starting_point()

from sys import stdin
from bisect import bisect_right as br
input=stdin.readline
n,k,m,t=list(map(int,input().split()))
ans=[0]*n
ans[k-1]=1
#print(ans)
for i in range(t):
    d,u=list(map(int,input().split()))
    if d==0:
        a=ans[:u]
        b=ans[u:]
        if 1 in a:
            print(len(a),a.index(1)+1)
            ans=a[:]
        else:
            print(len(b),b.index(1)+1)
            ans=b[:]
    else:
        ans=ans[:u-1]+[0]+ans[u-1:]
        print(len(ans),ans.index(1)+1)
    #print(ans)


n,k,m,t = list(map(int,input().split()))
usize = n
for i in range(t):
	a,b = list(map(int,input().split()))
	if (a == 0):
		if (k <= b):
			usize = b
		else:
			usize = usize - b
			k = k - b
	else:
		if (k >= b):
			k = k + 1
		usize = usize + 1
	print(usize,k)


n, k, m, t = list(map(int, input().split(' ')))

# n = nb univ
# k = doc pos
# m = max nb univ

for _ in range(t):
    op, pos = list(map(int, input().split(' ')))
    if op == 1:
        if k >= pos:
            k += 1
        n += 1
    else:
        if k > pos:
            n -= pos
            k -= pos
        else:
            n = pos

    print(n, k)


n, k, m, t = list(map(int, input().split()))

for i in range(t):
    a, b  = list(map(int, input().split()))
    if a:
        if b<=k and n+1<=m:
            k+=1
            n+=1
        elif b>k and n+1<=m:
            n+=1

    else:
        if b<k:
            k-=b
            n-=b
        elif b>=k:
            n-=(n-b)
    print(n, k)


n,k,m,t=map(int,input().split())
for i in range(t):
	bj,p=map(int,input().split())
	if bj==0:
		n1=p
		n2=n-p
		if k>p:
			n=n2
			k=k-p
		elif k<=p:
			n=n1
	elif bj==1:
		if k>=p:
			k=k+1
			n=n+1
		elif k<p:
			n=n+1
	print(n,k,sep=' ')
			
		

n, k, m, t = map(int, input().split())
l = [0] * n
l[k - 1] = 1
for _ in range(t):
    c, i = map(int, input().split())
    if c == 0:
        a, b = l[:i], l[i:]
        if 1 in a: l = a
        else: l = b
    else:
        l.insert(i - 1, 0)
    # print(l)
    print(len(l), l.index(1) + 1)

n, k, m, t = list(map(int, input().split()))
for tt in range(t):
	op, i = list(map(int, input().split()))
	if op == 1:
		if i <= k:
			k += 1
		n += 1
	elif op == 0:
		if i < k:
			k -= i
			n -= i
		else:
			n -= n - i
	print(n, k)


n, k, m, t = list(map(int, input().split()))

for req in range(t):
    q, i = list(map(int, input().split()))
    if q == 1:
        n += 1
        if i <= k:
            k += 1
    else:
        if i >= k:
            n = i
        else:
            n -= i
            k -= i
    print(n, k)


n,k,m,t = list(map(int,input().split()))
for _ in range(t):
    c,i = list(map(int,input().split()))
    if(c == 1):
        n += 1
        if(i <= k): k += 1
    if(c == 0):
        if(i < k):
            k -= i
            n -= i
        else:
            n = i
    print(n,k)


nkmt=[int(k) for k in input().split()]
n= nkmt[0]
k = nkmt[1]
m = nkmt[2]
t = nkmt[3]
arr_d=[]
uni=[0] * n
uni[k - 1] = 1 
for _ in range(t):
    i = [int(k) for k in input().split()]
    
    if i[0]==1:
        uni.insert(i[1]-1,0)
    if i[0]==0:
        uni_temp1=uni[:i[1]]
        uni_temp2=uni[i[1]:]
        if 1 in uni_temp1:
            uni=uni_temp1
        else:
            uni=uni_temp2
    print(len(uni), end=' ')
    print(uni.index(1)+1)   
        




#N = int(input())

#N,B = [int(x) for x in arr.split(' ')]

arr = input()
N,K,M,T = [int(x) for x in arr.split(' ')]

uni = [0]*N

uni[K-1] = 1

for i in range(T):
    arr = input()
    move,pos = [int(x) for x in arr.split(' ')]
    
    if move==0:
        u1 = uni[:pos]
        u2 = uni[pos:]
        if 1 in u1:
            uni = u1
        else:
            uni = u2
            K -= len(u1)
        
        print(len(uni),K)
        
    else:
        p = pos-1
        u1 = uni[:p]
        u2 = uni[p:]
        uni = u1 + [0] + u2
        
        
        if 1 in u2:
            K += 1
            
        print(len(uni),K)
        
        
            
    


n , k , m , t = map(int,input().split())

l = [1]*n

l[k-1] = "doc"

for i in range(t):
    op , idx = map(int,input().split())
    if op == 0:
        if idx < k:
            while idx:
                l.pop(0)
                idx -= 1
        else:
            idx = len(l) - idx
            while idx:
                l.pop()
                idx -= 1

        
        y = len(l)
        print(y,end=' ')
        for x in range(y):
            if l[x] == "doc":
                k = x+1
                print(x+1)
                break

    else:
        l.insert(idx-1,1)

        y = len(l)
        print(y,end=' ')
        for x in range(y):
            if l[x] == "doc":
                k = x+1
                print(x+1)
                break
    # print(l)

n, k, m, t = map(int, input().split())
for i in range(t):
    type, i = map(int, input().split())
    if type:
        n += 1
        if k >= i:
            k += 1
    else:
        if k >= i + 1:
            k -= i
            n -= i
        else:
            n = i
    print(n, k)

n, k, m, t = map(int, input().split())
for j in range(t):
    a, i = map(int, input().split())
    if a:
        n += 1
        if i <= k:
            k += 1
    else:
        if i >= k:
            n = i
        else:
            n -= i
            k -= i
    print(n, k)

n, k, m, t = input().split()
n, k, m, t = int(n), int(k), int(m), int(t)

for i in range(t):
    what, pos = input().split()
    what, pos = int(what), int(pos)
    if what == 0:
        if pos >= k:
            n = pos
        else:
            n = n-pos
            k = k-pos
    else:
        n += 1
        if pos <= k:
            k += 1
    print(n, end=" ")
    print(k)




import sys


def main():
    input = sys.stdin.readline()
    n, k, m, t = [int(j) for j in input.split()]
    for i in range(t):
        input = sys.stdin.readline()
        d, c = [int(j) for j in input.split()]
        if d == 0:
            if c<k:
                n -= c
                k -= c
            else:
                n = c
        else:
            if c<=k:
                k += 1
            n += 1
        print(n,k)

def __starting_point():
    main()
__starting_point()

n,k,m,t = map(int,input().split())
pos = k
l = n
for tt in range(t):
    ty,val = map(int,input().split())
    if ty==0:
        if val < pos:
            pos = pos-val
            l = l-val
        else :
            l = val
    else :
        l+=1
        if val <= pos:
            pos+=1
    print(l,pos)

n,pos,maxx,que=list(map(int,input().split()))
initial=[1]*n
for x in range(que):
    a,b=list(map(int,input().split()))
    if a==1:
        lam=b
        if pos<lam:
            pass
        else:
            pos+=1
        initial.insert(lam-1,1)
        n+=1
        print(n,pos)
    else:
        jam=b
        ham=b+1
        if pos<=jam:
            initial=initial[0:jam]
            n=len(initial)
        else:
            initial=initial[ham-1:]
            n=len(initial)
            pos-=jam
        print(n,pos)