from heapq import heappush, heappop

inputs = lambda: list(map(int, input().split()))

n, q = inputs()

n += 1

que = [(0, 1, -1)]

data = [0] * n

T = [-1] * n

for t in range(q):

    a, v = inputs()

    data[a] += v

    T[a] = t



    heappush(que, (-data[a], a, t))

    while 1:

        v, k, p = heappop(que)

        if T[k] == p:

            print(k, -v)

            heappush(que, (v, k, p))

            break
from heapq import heappush, heappop

inputs = lambda: list(map(int, input().split()))

n, q = inputs()

n += 1

que = [(0, 1, -1)]

data = [0] * n

T = [-1] * n

for t in range(q):

    a, v = inputs()

    data[a] += v

    T[a] = t



    heappush(que, (-data[a], a, t))

    v, k, p = que[0]

    while T[k]!=p:

        heappop(que)

        v, k, p = que[0]

    print(k, -v)
from heapq import heappush, heappop

inputs = lambda: list(map(int, input().split()))
n, q = inputs()
n += 1
que = [(0, 1, -1)]
data = [0] * n
T = [-1] * n
for t in range(q):
    a, v = inputs()
    data[a] += v
    T[a] = t
    heappush(que, (-data[a], a, t))
    while 1:
        v, k, p = heappop(que)
        if T[k] == p:
            print(k, -v)
            heappush(que, (v, k, p))
            break

from heapq import heappush, heappop

inputs = lambda: list(map(int, input().split()))
n, q = inputs()
n += 1
que = [(0, 1, -1)]
data = [0] * n
T = [-1] * n
for t in range(q):
    a, v = inputs()
    data[a] += v
    T[a] = t
    heappush(que, (-data[a], a, t))
    v, k, p = que[0]
    while T[k] != p:
        heappop(que)
        v, k, p = que[0]
    print(k, -v)

-    while 1: -        v, k, p = heappop(que) -        if T[k] == p: -            print(k, -v) -            heappush(que, (v, k, p)) -            break +    v, k, p = que[0] +    while T[k] != p: +        heappop(que) +        v, k, p = que[0] +    print(k, -v)