import bisect



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

pref = [[] for i in range(N)]

id = [[]] * M



for i in range(M):

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

  id[i] = [p,y]

  pref[p - 1].append(y)

  #pref[p - 1] = sorted(pref[p - 1])



for i in range(N):

  pref[i] = sorted(pref[i])



orders = [0] * N



for i in range(M):

  p = id[i][0] - 1

  y = id[i][1]

  order = str(bisect.bisect_left(pref[p],y) + 1)

  city = str(p + 1)

  ID = ""

  ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order

  print(ID)

import bisect



def main():

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

  pref = [[] for i in range(N)]

  id = [[]] * M

  

  for i in range(M):

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

    id[i] = [p,y]

    pref[p - 1].append(y)

    #pref[p - 1] = sorted(pref[p - 1])

  

  for i in range(N):

    pref[i] = sorted(pref[i])

  

  orders = [0] * N

  

  for i in range(M):

    p = id[i][0] - 1

    y = id[i][1]

    order = str(bisect.bisect_left(pref[p],y) + 1)

    city = str(p + 1)

    ID = ""

    ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order

    print(ID)



if __name__ == '__main__':

  main()
import bisect

N, M = list(map(int, input().split()))
pref = [[] for i in range(N)]
id = [[]] * M
for i in range(M):
    p, y = list(map(int, input().split()))
    id[i] = [p, y]
    pref[p - 1].append(y)
    # pref[p - 1] = sorted(pref[p - 1])
for i in range(N):
    pref[i] = sorted(pref[i])
orders = [0] * N
for i in range(M):
    p = id[i][0] - 1
    y = id[i][1]
    order = str(bisect.bisect_left(pref[p], y) + 1)
    city = str(p + 1)
    ID = ""
    ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
    print(ID)

import bisect


def main():
    N, M = list(map(int, input().split()))
    pref = [[] for i in range(N)]
    id = [[]] * M
    for i in range(M):
        p, y = list(map(int, input().split()))
        id[i] = [p, y]
        pref[p - 1].append(y)
        # pref[p - 1] = sorted(pref[p - 1])
    for i in range(N):
        pref[i] = sorted(pref[i])
    orders = [0] * N
    for i in range(M):
        p = id[i][0] - 1
        y = id[i][1]
        order = str(bisect.bisect_left(pref[p], y) + 1)
        city = str(p + 1)
        ID = ""
        ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order
        print(ID)


if __name__ == "__main__":
    main()

-N, M = list(map(int, input().split())) -pref = [[] for i in range(N)] -id = [[]] * M -for i in range(M): -    p, y = list(map(int, input().split())) -    id[i] = [p, y] -    pref[p - 1].append(y) -    # pref[p - 1] = sorted(pref[p - 1]) -for i in range(N): -    pref[i] = sorted(pref[i]) -orders = [0] * N -for i in range(M): -    p = id[i][0] - 1 -    y = id[i][1] -    order = str(bisect.bisect_left(pref[p], y) + 1) -    city = str(p + 1) -    ID = "" -    ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order -    print(ID) + +def main(): +    N, M = list(map(int, input().split())) +    pref = [[] for i in range(N)] +    id = [[]] * M +    for i in range(M): +        p, y = list(map(int, input().split())) +        id[i] = [p, y] +        pref[p - 1].append(y) +        # pref[p - 1] = sorted(pref[p - 1]) +    for i in range(N): +        pref[i] = sorted(pref[i]) +    orders = [0] * N +    for i in range(M): +        p = id[i][0] - 1 +        y = id[i][1] +        order = str(bisect.bisect_left(pref[p], y) + 1) +        city = str(p + 1) +        ID = "" +        ID += "0" * (6 - len(city)) + city + "0" * (6 - len(order)) + order +        print(ID) + + +if __name__ == "__main__": +    main()