output_description: Print the ID numbers for all the cities, in ascending order of indices (City
  1, City 2, ...).
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      P_1 Y_1
      :
      P_M Y_M
attempt: import sys, re
  from math import ceil, floor, sqrt, pi, factorial, gcd
  from copy import deepcopy
  from collections import Counter, deque
  from heapq import heapify, heappop, heappush
  from itertools import accumulate, product, combinations, combinations_with_replacement
  from bisect import bisect, bisect_left
  from functools import reduce
  from decimal import Decimal, getcontext
  
  
  # input = sys.stdin.readline
  def i_input():
      return int(input())
  
  
  def i_map():
      return map(int, input().split())
  
  
  def i_list():
      return list(i_map())
  
  
  def i_row(N):
      return [i_input() for _ in range(N)]
  
  
  def i_row_list(N):
      return [i_list() for _ in range(N)]
  
  
  def s_input():
      return input()
  
  
  def s_map():
      return input().split()
  
  
  def s_list():
      return list(s_map())
  
  
  def s_row(N):
      return [s_input for _ in range(N)]
  
  
  def s_row_list(N):
      return [s_list() for _ in range(N)]
  
  
  def Yes():
      print("Yes")
  
  
  def No():
      print("No")
  
  
  def YES():
      print("YES")
  
  
  def NO():
      print("NO")
  
  
  def lcm(a, b):
      return a * b // gcd(a, b)
  
  
  sys.setrecursionlimit(10**6)
  INF = float("inf")
  MOD = 10**9 + 7
  num_list = []
  str_list = []
  
  
  def main():
      n, m = i_map()
      for i in range(m):
          p, y = i_map()
          num_list.append([p, y, i])
  
      sorted_data = sorted(num_list, key=lambda x: x[0])
      sorted_data = sorted(sorted_data, key=lambda x: x[1])
  
      ans_list = []
      count_index = 0
      for num in sorted_data:
          if count_index != num[0]:
              count_index = num[0]
              count_num = 1
          else:
              count_num += 1
          ans_num = str(num[0]).zfill(6) + str(count_num).zfill(6)
          ans_list.append([num[2], ans_num])
  
      ans_list.sort()
  
      for ans in ans_list:
          print(ans[1])
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  In Republic of Atcoder, there are N prefectures, and a total of M cities that
  belong to those prefectures.
  
  City i is established in year Y_i and belongs to Prefecture P_i.
  
  You can assume that there are no multiple cities that are established in the
  same year.
  
  It is decided to allocate a 12-digit ID number to each city.
  
  If City i is the x-th established city among the cities that belong to
  Prefecture i, the first six digits of the ID number of City i is P_i, and the
  last six digits of the ID number is x.
  
  Here, if P_i or x (or both) has less than six digits, zeros are added to the
  left until it has six digits.
  
  Find the ID numbers for all the cities.
  
  Note that there can be a prefecture with no cities.
samples: [{"input": "2 3\n    1 32\n    2 63\n    1 12", "output": "000001000002\n    000002000001\n    000001000001\n    \n\n  * As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.\n  * As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.\n  * As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.\n\n* * *"}, {"input": "2 3\n    2 55\n    2 77\n    2 99", "output": "000002000001\n    000002000002\n    000002000003"}]