def inputInts
    gets.chomp.split(" ").map(&:to_i)
end

def getId(p, x)
    format('%06d', p) + format('%06d', x)
end

@N, @M = inputInts
@pres = {}
@cities = {}

(1..@N).each do |i|
    @pres[i] = []
end

(1..@M).each do |i|
    p, y = inputInts
    @pres[p] << i
    @cities[i] = [p, y]
end

# sort cities by founded year
(1..@N).each do |i|
    @pres[i].sort {|a, b| @cities[a][1] <=> @cities[b][1] }
end

# add indexes to cities
(1..@N).each do |i|
    @pres[i].each_with_index do |city, i|
        @cities[city] << i + 1
    end
end

(1..@M).each do |i|
    city = @cities[i]
    puts getId(city[0], city[2])
end
