Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
P = []
for i, a in enumerate(A):
    a[0], a[1] = list(map(int, input().split()))
    a[2] = i
    if not a[0] in P:
        P.append(a[0])

P_counts = [0]*len(P)
sorted_A = sorted(A, key=itemgetter(1))

for a in sorted_A:
    idx = P.index(a[0])
    P_counts[idx] += 1
    a[3] = str(a[0]).zfill(6) + str(P_counts[idx]).zfill(6)

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print(b[3])


Fixed submission:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

sorted_A = sorted(A, key=itemgetter(1))

P_num = [1]*N
for a in sorted_A:
    y = a[0]
    a[3] = P_num[y-1]
    P_num[y-1] += 1

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print("%06d%06d" % (b[0], b[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

P = list(set([a[0] for a in A]))
P_counts = [0]*len(P)
sorted_A = sorted(A, key=itemgetter(1))

for a in sorted_A:
    idx = P.index(a[0])
    P_counts[idx] += 1
    a[3] = str(a[0]).zfill(6) + str(P_counts[idx]).zfill(6)

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print(b[3])

Fixed submission:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

sorted_A = sorted(A, key=itemgetter(1))

P_num = [1]*N
for a in sorted_A:
    y = a[0]
    a[3] = P_num[y-1]
    P_num[y-1] += 1

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print("%06d%06d" % (b[0], b[3]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [0]*M
P = [0] * M
for i in range(M):
    A[i] = [0]*4
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i
    P[i] = A[i][0]

p_unique = list(set(P))
p_unique_count = [0]*len(p_unique)
a = sorted(A, key=itemgetter(1))


def create_number(p, x):
    return str(p).zfill(6) + str(x).zfill(6)


for i in range(M):
    idx = p_unique.index(a[i][0])
    p_unique_count[idx] += 1
    number = create_number(a[i][0], p_unique_count[idx])
    a[i][3] = number

B = sorted(a, key=itemgetter(2))
for b in B:
    print(b[3])


Fixed submission:
# -*- coding: utf-8 -*-
from operator import itemgetter

N, M = list(map(int, input().split()))
A = [[0] * 4 for i in range(M)]
for i in range(M):
    A[i][0], A[i][1] = list(map(int, input().split()))
    A[i][2] = i

sorted_A = sorted(A, key=itemgetter(1))

P_num = [1]*N
for a in sorted_A:
    y = a[0]
    a[3] = P_num[y-1]
    P_num[y-1] += 1

B = sorted(sorted_A, key=itemgetter(2))
for b in B:
    print("%06d%06d" % (b[0], b[3]))