# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

city_year_list = inputs[1..-1]
p city_year_list if $debugFlag

# body
categorized = []
city_year_list.each do |e_i|
  if categorized[e_i[0]] == nil
    categorized[e_i[0]] = [e_i[1]]
  else
    categorized[e_i[0]] << e_i[1]
  end
end

categorized.each do |c_i|
  c_i.sort! if c_i
end

p categorized if $debugFlag

city_year_list.each do |c_i|
  printf("%06d%06d\n", c_i[0], categorized[c_i[0]].index(c_i[1]) + 1)
end


