# AOJ 0099 Surf Smelt Fishing Contest II

# Python3 2018.6.22 bal4u



import heapq

MAX = 1000000

SFT = 20	# 2**20 = 1048576 > MAX

Q = []



# tbl[0:キー, 1:Magic]

tbl = [[0 for j in range(2)] for i in range(MAX+2)]

n, q = list(map(int, input().split()))

for i in range(q):

	id, v = list(map(int, input().split()))

	tbl[id][0] += v

	tbl[id][1] += 1

	heapq.heappush(Q, ((-tbl[id][0] << SFT)|id, id, tbl[id][1]))

	while 1:

		f, id, c = Q[0]       # 要素の確認のみ

		if tbl[id][1] == c:

			print((id, tbl[id][0]))

			break

		heapq.heappop(Q)

# AOJ 0099 Surf Smelt Fishing Contest II

# Python3 2018.6.22 bal4u



import heapq

MAX = 1000000

SFT = 20	# 2**20 = 1048576 > MAX

Q = []



# tbl[0:キー, 1:Magic]

n, q = list(map(int, input().split()))

tbl = [0]*(n+1)

for i in range(q):

	id, v = list(map(int, input().split()))

	tbl[id] += v

	heapq.heappush(Q, ((-tbl[id] << SFT)|id, id, tbl[id]))

	while 1:

		f, id, v = Q[0]       # 要素の確認のみ

		if tbl[id] == v:

			print((id, v))

			break

		heapq.heappop(Q)

# AOJ 0099 Surf Smelt Fishing Contest II
# Python3 2018.6.22 bal4u
import heapq

MAX = 1000000
SFT = 20  # 2**20 = 1048576 > MAX
Q = []
# tbl[0:キー, 1:Magic]
tbl = [[0 for j in range(2)] for i in range(MAX + 2)]
n, q = list(map(int, input().split()))
for i in range(q):
    id, v = list(map(int, input().split()))
    tbl[id][0] += v
    tbl[id][1] += 1
    heapq.heappush(Q, ((-tbl[id][0] << SFT) | id, id, tbl[id][1]))
    while 1:
        f, id, c = Q[0]  # 要素の確認のみ
        if tbl[id][1] == c:
            print((id, tbl[id][0]))
            break
        heapq.heappop(Q)

# AOJ 0099 Surf Smelt Fishing Contest II
# Python3 2018.6.22 bal4u
import heapq

MAX = 1000000
SFT = 20  # 2**20 = 1048576 > MAX
Q = []
# tbl[0:キー, 1:Magic]
n, q = list(map(int, input().split()))
tbl = [0] * (n + 1)
for i in range(q):
    id, v = list(map(int, input().split()))
    tbl[id] += v
    heapq.heappush(Q, ((-tbl[id] << SFT) | id, id, tbl[id]))
    while 1:
        f, id, v = Q[0]  # 要素の確認のみ
        if tbl[id] == v:
            print((id, v))
            break
        heapq.heappop(Q)

-tbl = [[0 for j in range(2)] for i in range(MAX + 2)] +tbl = [0] * (n + 1) -    tbl[id][0] += v -    tbl[id][1] += 1 -    heapq.heappush(Q, ((-tbl[id][0] << SFT) | id, id, tbl[id][1])) +    tbl[id] += v +    heapq.heappush(Q, ((-tbl[id] << SFT) | id, id, tbl[id])) -        f, id, c = Q[0]  # 要素の確認のみ -        if tbl[id][1] == c: -            print((id, tbl[id][0])) +        f, id, v = Q[0]  # 要素の確認のみ +        if tbl[id] == v: +            print((id, v))