Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

array = [list(map(int, input().split())) for i in range(m)]
array_ans = []
myset = set()

for i in range(m):
    myset.add(array[i][0])


for i in myset:
    array_temp = [[array[j][0], array[j][1], j] for j in range(m) if array[j][0] == i]
    array_temp = sorted(array_temp, key=lambda x: x[1])
    for j in range(len(array_temp)):
        array_temp[j][1] = j + 1
    array_ans.extend(array_temp)

array_ans = sorted(array_ans, key=lambda x: x[2])


for i in range(m):
    out = '%06d' % array_ans[i][0] + '%06d' % array_ans[i][1]
    print(out)


Fixed submission:
n, m = map(int, input().split())

array = []
for i in range(m):
    temp = list(map(int, input().split()))
    temp.append(i)
    array.append(temp)

array = sorted(array, key=lambda x: (x[0], x[1]))

count = 1
eq = True

for i in range(m):
    if eq is False:
        count = 1
    array[i][1] = count
    count += 1
    if i != m - 1:
        if array[i][0] == array[i + 1][0]:
            eq = True
        else:
            eq = False

array = sorted(array, key=lambda x: x[2])

for i in range(m):
    out = '%06d' % array[i][0] + '%06d' % array[i][1]
    print(out)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

array = [list(map(int, input().split())) for i in range(M)]
myset = set()

for i in range(M):
    array[i][0] = '%06d' % array[i][0]
    myset.add(array[i][0])

for i in myset:
    array2 = [array[j][1] for j in range(M) if array[j][0] == i]
    array2 = sorted(array2)
    for j in range(M):
        for k in range(len(array2)):
            if array[j][0] == i and array[j][1] == array2[k]:
                array[j][1] = '%06d' % (k + 1)
                break

for i in range(M):
    print(str(array[i][0]) + str(array[i][1]))


Fixed submission:
n, m = map(int, input().split())

array = []
for i in range(m):
    temp = list(map(int, input().split()))
    temp.append(i)
    array.append(temp)

array = sorted(array, key=lambda x: (x[0], x[1]))

count = 1
eq = True

for i in range(m):
    if eq is False:
        count = 1
    array[i][1] = count
    count += 1
    if i != m - 1:
        if array[i][0] == array[i + 1][0]:
            eq = True
        else:
            eq = False

array = sorted(array, key=lambda x: x[2])

for i in range(m):
    out = '%06d' % array[i][0] + '%06d' % array[i][1]
    print(out)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

array = [list(map(int, input().split())) for i in range(M)]
myset = set()

for i in range(M):
    array[i][0] = '%06d' % array[i][0]
    myset.add(array[i][0])

for i in myset:
    array2 = [array[j][1] for j in range(M) if array[j][0] == i]
    array2 = sorted(array2)
    for j in range(M):
        for k in range(len(array2)):
            if array[j][0] == i and array[j][1] == array2[k]:
                array[j][1] = '%06d' % (k + 1)
for i in range(M):
    print(str(array[i][0]) + str(array[i][1]))


Fixed submission:
n, m = map(int, input().split())

array = []
for i in range(m):
    temp = list(map(int, input().split()))
    temp.append(i)
    array.append(temp)

array = sorted(array, key=lambda x: (x[0], x[1]))

count = 1
eq = True

for i in range(m):
    if eq is False:
        count = 1
    array[i][1] = count
    count += 1
    if i != m - 1:
        if array[i][0] == array[i + 1][0]:
            eq = True
        else:
            eq = False

array = sorted(array, key=lambda x: x[2])

for i in range(m):
    out = '%06d' % array[i][0] + '%06d' % array[i][1]
    print(out)