import numpy as np



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

P = []

Y = []

for _ in range(M):

    p, y = list(map(int, input().split()))

    P.append(p)

    Y.append(y)

P = np.array(P)

Y = np.array(Y)

PY = np.c_[P, Y]

sort_ind = np.argsort(Y)



PY_sort = PY[sort_ind]

count = [0] * (int(1e+5) + 1)

id_list = []

for p, y in PY_sort:

    count[p] += 1

    id_list.append(str(p).zfill(6) + str(count[p]).zfill(6))



id_list = np.array(id_list)

id_list = id_list[np.argsort(sort_ind)]

for city_id in id_list:

    print(city_id)
import bisect

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

P, Y = [], []

pref = [[] for _ in range(N+1)] # non-0-indexed

for m in range(M):

    p,y = list(map(int, input().split()))

    P.append(p)

    Y.append(y)

    pref[p].append(y)

for i, p in enumerate(pref):

    pref[i] = sorted(p)

    

for p,y in zip(P,Y):

    ans = "{:0>6}".format(p)

    i = bisect.bisect(pref[p], y)

    ans += "{:0>6}".format(i)

    print(ans)





import numpy as np

N, M = list(map(int, input().split()))
P = []
Y = []
for _ in range(M):
    p, y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
P = np.array(P)
Y = np.array(Y)
PY = np.c_[P, Y]
sort_ind = np.argsort(Y)
PY_sort = PY[sort_ind]
count = [0] * (int(1e5) + 1)
id_list = []
for p, y in PY_sort:
    count[p] += 1
    id_list.append(str(p).zfill(6) + str(count[p]).zfill(6))
id_list = np.array(id_list)
id_list = id_list[np.argsort(sort_ind)]
for city_id in id_list:
    print(city_id)

import bisect

N, M = list(map(int, input().split()))
P, Y = [], []
pref = [[] for _ in range(N + 1)]  # non-0-indexed
for m in range(M):
    p, y = list(map(int, input().split()))
    P.append(p)
    Y.append(y)
    pref[p].append(y)
for i, p in enumerate(pref):
    pref[i] = sorted(p)
for p, y in zip(P, Y):
    ans = "{:0>6}".format(p)
    i = bisect.bisect(pref[p], y)
    ans += "{:0>6}".format(i)
    print(ans)

-import numpy as np +import bisect -P = [] -Y = [] -for _ in range(M): +P, Y = [], [] +pref = [[] for _ in range(N + 1)]  # non-0-indexed +for m in range(M): -P = np.array(P) -Y = np.array(Y) -PY = np.c_[P, Y] -sort_ind = np.argsort(Y) -PY_sort = PY[sort_ind] -count = [0] * (int(1e5) + 1) -id_list = [] -for p, y in PY_sort: -    count[p] += 1 -    id_list.append(str(p).zfill(6) + str(count[p]).zfill(6)) -id_list = np.array(id_list) -id_list = id_list[np.argsort(sort_ind)] -for city_id in id_list: -    print(city_id) +    pref[p].append(y) +for i, p in enumerate(pref): +    pref[i] = sorted(p) +for p, y in zip(P, Y): +    ans = "{:0>6}".format(p) +    i = bisect.bisect(pref[p], y) +    ans += "{:0>6}".format(i) +    print(ans)