Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math
input = sys.stdin.readline

N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[i][0]-1] += 1
    M_counter[i] = N_counter[PY[i][0]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Fixed submission:
N,M = map(int, input().split())

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


PY.sort(key=lambda val: val[2])
# print(PY)
PY.sort(key=lambda val: val[1])
# print(PY)
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])

# print(PY)

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[i][0]-1] += 1
    M_counter[i] = N_counter[PY[i][0]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Fixed submission:
N,M = map(int, input().split())

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


PY.sort(key=lambda val: val[2])
# print(PY)
PY.sort(key=lambda val: val[1])
# print(PY)
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])

# print(PY)

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[i][0]-1] += 1
    M_counter[i] = N_counter[PY[i][0]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Fixed submission:
N,M = map(int, input().split())

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


PY.sort(key=lambda val: val[2])
# print(PY)
PY.sort(key=lambda val: val[1])
# print(PY)
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])

# print(PY)

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])

for i in range(M):
    N_counter[PY[1]-1] += 1
    M_counter[i] = N_counter[PY[1]-1]

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)


Fixed submission:
N,M = map(int, input().split())

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


PY.sort(key=lambda val: val[2])
# print(PY)
PY.sort(key=lambda val: val[1])
# print(PY)
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])

# print(PY)

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_originals = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])
i = 0

for P,Y in PY:
    N_counter[P-1] += 1
    M_counter[i] = N_counter[P-1]
    i += 1

for i in PY_originals:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)


Fixed submission:
N,M = map(int, input().split())

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


PY.sort(key=lambda val: val[2])
# print(PY)
PY.sort(key=lambda val: val[1])
# print(PY)
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])

# print(PY)

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
PY = [list(map(int,input().split())) for _ in range(M)]
PY_original = tuple(PY)
N_counter = [0] * N
M_counter = [0] * M

PY.sort(key=lambda val: val[1])
i = 0

for P,Y in PY:
    N_counter[P-1] += 1
    M_counter[i] = N_counter[P-1]
    i += 1

for i in PY_original:
    ans = str(i[0]).zfill(6)+str(M_counter[PY.index(i)]).zfill(6)
    print(ans)

Fixed submission:
N,M = map(int, input().split())

PY = [[i] for i in range(1,M+1)]

for i in range(M):
    temp1, temp2 = map(int, input().split())
    PY[i].append(temp1)
    PY[i].append(temp2)


PY.sort(key=lambda val: val[2])
# print(PY)
PY.sort(key=lambda val: val[1])
# print(PY)
city = 0

for i, value in enumerate(PY):
    if value[1] != city:
        j = 0
    j += 1
    value.append(j)
    city = value[1]

PY.sort(key=lambda val:val[0])

# print(PY)

for i in PY:
    ans = str(i[1]).zfill(6)+str(i[3]).zfill(6)
    print(ans)