Buggy python submission (verdict: Runtime Error):
from bisect import bisect,bisect_left


N,M = map(int,input().split())

d1 = {}
d2 = {}
for i in range(M):
    PY = list(map(int,input().split()))
    tmp = d1.get(PY[0],[])
    ins_pos = bisect(tmp,PY[1])
    tmp.insert(ins_pos,PY[1])
    d1[PY[0]] = tmp

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(bisect_left(d[py[0]],py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)


Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split()))+[i] for i in range(M)]

num = [0]*N
ans = [""]*M

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

for p,y,i in PY:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import insort,bisect_left
input_lines = sys.stdin.readlines()
N,M = map(int,input_lines[0].split())
PY = [list(map(int,input_lines[i+1].split())) for i in range(M)]

d = {}

for py in PY:
    tmp = d.get(py[0],[])
    insort(tmp,py[1])
    d[py[0]] = tmp

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(bisect_left(d[py[0]],py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)


Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split()))+[i] for i in range(M)]

num = [0]*N
ans = [""]*M

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

for p,y,i in PY:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort,bisect_left

N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]

d = {}

for py in PY:
    tmp = d.get(py[0],[])
    insort(tmp,py[1])
    d[py[0]] = tmp

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(bisect_left(d[py[0]],py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)


Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split()))+[i] for i in range(M)]

num = [0]*N
ans = [""]*M

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

for p,y,i in PY:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for a in ans:
    print(a)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

N,M = map(int,input().split())
PY = [list(map(int,input().split())) for _ in range(M)]

d = {}

for py in PY:
    d[py[0]] = d.get(py[0],[])+[py[1]]

for k in d:
    d[k].sort()

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(bisect_left(d[py[0]],py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)


Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split()))+[i] for i in range(M)]

num = [0]*N
ans = [""]*M

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

for p,y,i in PY:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for a in ans:
    print(a)

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

d = {}

for py in PY:
    d[py[0]] = d.get(py[0],[])+[py[1]]

for k in d:
    d[k].sort()

for py in PY:
    s1 = str(py[0])
    s1 = ("0"*(6-len(s1)))+s1
    s2 = str(d[py[0]].index(py[1])+1)
    s2 = ("0"*(6-len(s2)))+s2

    print(s1+s2)


Fixed submission:
N,M = map(int,input().split())
PY = [list(map(int,input().split()))+[i] for i in range(M)]

num = [0]*N
ans = [""]*M

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

for p,y,i in PY:
    num[p-1] += 1
    ans[i] = str(p).zfill(6) + str(num[p-1]).zfill(6)

for a in ans:
    print(a)