Buggy python submission (verdict: Time Limit Exceeded):
from collections import OrderedDict
n, q = [int(el) for el in input().split(' ')]
data = {}
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    if a in data:
        data[a] += v
    else:
        data[a] = v
    tmp = OrderedDict(sorted(data.items(), key=lambda t: t[0]))
    result = OrderedDict(sorted(tmp.items(), key=lambda t: t[1], reverse=True))
    print(*result.popitem(False))

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter
from collections import OrderedDict
n, q = [int(el) for el in input().split(' ')]
data = OrderedDict({i:0 for i in range(n,0,-1)})
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a] += v
    print(*max(data.items(), key=itemgetter(1)))

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import OrderedDict
n, q = [int(el) for el in input().split(' ')]
data = OrderedDict({i:0 for i in range(n,0,-1)})
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a] += v
    result = OrderedDict(sorted(data.items(), key=lambda t: t[1], reverse=True))
    print(*result.popitem(False))

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    result = max(data)
    print(data.index(result)+1, result)

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v < 0:
        result = ex_result
    else:
        result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v < 0:
        result = ex_result
    else:
        result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v < 0:
        result = ex_result
    else:
        result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v < 0:
        result = ex_result
    else:
        result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v < 0:
        result = ex_result
    else:
        result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v < 0:
        result = ex_result
    else:
        result = max(data)
    print(data.index(result)+1, result)
    ex_result = result

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    result = max(data)
    print(data.index(result)+1, result)

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
ex_index = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if ex_index != a:
        if v < 0: result = ex_result
        else: result = max(ex_result, data[a-1])
    elif ex_index == a:
        if v > 0: result = data[a-1]
        else: result = max(data)
    index = data.index(result)+1
    print(index, result)
    ex_result = result
    ex_index = index

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result, exx_result = 0,0
ex_index = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if ex_index != a:
        if v < 0: result = ex_result
        else: result = max(ex_result, data[a-1])
    elif ex_index == a:
        if v > 0: result = data[a-1]
        else: result = max(data[a-1], exx_result)
    index = data.index(result)+1
    print(index, result)
    exx_result = ex_result
    ex_result = result
    ex_index = index

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result, exx_result = 0,0
ex_index = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if ex_index != a:
        if v < 0: result = ex_result
        else: result = max(ex_result, data[a-1])
    elif ex_index == a:
        if v > 0: result = data[a-1]
        else: result = max(exx_result, data[a-1])
    index = data.index(result)+1
    print(index, result)
    exx_result = ex_result
    ex_result = result
    ex_index = index

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result,exx_result = 0,0
ex_index = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if ex_index != a:
        if v < 0: result = ex_result
        else: result = max(ex_result, data[a-1])
    elif ex_index == a:
        if v > 0: result = data[a-1]
        else: result = max(exx_result, data[a-1])
    index = data.index(result)+1
    print(index, result)
    exx_result = ex_result
    ex_result = result
    ex_index = index

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Runtime Error):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result, exx_result = 0, 0
ex_index, exx_index  = 0, 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if ex_index != a:
        if v < 0: result = ex_result
        else: result = max(ex_result, data[a-1])
    else:
        if v > 0: result = data[a-1]
        else:
            if exx_index == a: result = max(data)
            else: result = max(exx_result, data[a-1])
    index = data.index(result) + 1
    print(index, result)
    exx_result = ex_result
    ex_result = result
    exx_index = ex_index
    ex_index = index

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)

Buggy python submission (verdict: Time Limit Exceeded):
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
ex_result = 0
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    result = max(data)
    print(data.index(result)+1, result)

Fixed submission:
n, q = [int(el) for el in input().split(' ')]
data = [0] * n
result, index = 0, 1
for _ in range(q):
    a, v = [int(el) for el in input().split(' ')]
    data[a-1] += v
    if v > 0:
        if result < data[a-1]:
            result, index = data[a-1], a
        elif result == data[a-1]:
            index = min(index, a)
    else:
        if index == a:
            result = max(data)
            index = data.index(result) + 1
    print(index, result)