Buggy python submission (verdict: Runtime Error):
from itertools import chain
import numpy as np
import pandas as pd


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

P = [0] * N

I = list(range(M))

Q = [None] * M
Y = [None] * M

for m in range(M):
    Q[m], Y[m] = map(int, input().split())
    P[Q[m]-1] += 1

D = zip(I, Q, Y)
D = sorted(D, key=lambda x: [x[1], x[2]])
I, Q, Y = map(list, zip(*D))

print(P)

P = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

print(P)

D = zip(I, Q, Y, P)
D = sorted(D, key=lambda x: x[0])
I, Q, Y, P = map(list, zip(*D))

print(P)

for i in range(M):
    print('%06d%06d' % (Q[i], P[i]))


Fixed submission:
from itertools import chain


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

P = [0] * N

I = list(range(M))

Q = [None] * M
Y = [None] * M

for m in range(M):
    Q[m], Y[m] = map(int, input().split())
    P[Q[m]-1] += 1

D = zip(I, Q, Y)
D = sorted(D, key=lambda x: [x[1], x[2]])
I, Q, Y = map(list, zip(*D))

P = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

D = zip(I, Q, Y, P)
D = sorted(D, key=lambda x: x[0])
I, Q, Y, P = map(list, zip(*D))

for i in range(M):
    print('%06d%06d' % (Q[i], P[i]))

Buggy python submission (verdict: Runtime Error):
from itertools import chain
import numpy as np
import pandas as pd


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

P = [0] * N
Q = [None] * M

for m in range(M):
    p, y    = map(int, input().split())
    P[p-1] += 1
    Q[m]    = p, y

D = pd.DataFrame(Q)
D = D.sort_values(by=[0, 1])

D[2] = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

D = D.sort_index()

X = D[0].values.tolist()
Y = D[2].values.tolist()

for i in range(M):
    print('%06d%06d' % (X[i], Y[i]))


Fixed submission:
from itertools import chain


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

P = [0] * N

I = list(range(M))

Q = [None] * M
Y = [None] * M

for m in range(M):
    Q[m], Y[m] = map(int, input().split())
    P[Q[m]-1] += 1

D = zip(I, Q, Y)
D = sorted(D, key=lambda x: [x[1], x[2]])
I, Q, Y = map(list, zip(*D))

P = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

D = zip(I, Q, Y, P)
D = sorted(D, key=lambda x: x[0])
I, Q, Y, P = map(list, zip(*D))

for i in range(M):
    print('%06d%06d' % (Q[i], P[i]))

Buggy python submission (verdict: Runtime Error):
import numpy as np


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

P = [None] * M
Y = [None] * M

X = [None] * (N + 1)
Y = [None] * (N + 1)

for n in range(N + 1):
    X[n] = []

for m in range(M):
    P[m], Y[m] = map(int, input().split())
    X[P[m]] = X[P[m]] + [Y[m]]

for i in range(len(X)):
    Y[i] = (np.argsort(np.array(X[i]))).tolist()

for p in P:
    print('%06d%06d' % (p, 1 + Y[p].pop(0)))


Fixed submission:
from itertools import chain


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

P = [0] * N

I = list(range(M))

Q = [None] * M
Y = [None] * M

for m in range(M):
    Q[m], Y[m] = map(int, input().split())
    P[Q[m]-1] += 1

D = zip(I, Q, Y)
D = sorted(D, key=lambda x: [x[1], x[2]])
I, Q, Y = map(list, zip(*D))

P = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

D = zip(I, Q, Y, P)
D = sorted(D, key=lambda x: x[0])
I, Q, Y, P = map(list, zip(*D))

for i in range(M):
    print('%06d%06d' % (Q[i], P[i]))

Buggy python submission (verdict: Runtime Error):
import numpy as np


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

P = [None] * M
Y = [None] * M

X = [None] * (N + 1)
Y = [None] * (N + 1)

for n in range(N + 1):
    X[n] = []

for m in range(M):
    P[m], Y[m] = map(int, input().split())
    X[P[m]] = X[P[m]] + [Y[m]]

for i in range(len(X)):
    Y[i] = (np.argsort(np.array(X[i])) + 1).tolist()

for p in P:
    print('%06d%06d' % (p, Y[p].pop(0)))


Fixed submission:
from itertools import chain


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

P = [0] * N

I = list(range(M))

Q = [None] * M
Y = [None] * M

for m in range(M):
    Q[m], Y[m] = map(int, input().split())
    P[Q[m]-1] += 1

D = zip(I, Q, Y)
D = sorted(D, key=lambda x: [x[1], x[2]])
I, Q, Y = map(list, zip(*D))

P = list(chain.from_iterable([list(range(1, p+1)) for p in P]))

D = zip(I, Q, Y, P)
D = sorted(D, key=lambda x: x[0])
I, Q, Y, P = map(list, zip(*D))

for i in range(M):
    print('%06d%06d' % (Q[i], P[i]))