'use strict'
function main(input) {
  input = input.split('\n')
  input.shift()
  let count = []
  input = input
    .map(c => {
      let arr = c.split(' ').map(w => w - 0)
      if (count[arr[0]] === undefined) count[arr[0]] = []
      count[arr[0]].push(arr[1])
      return arr
    })
  count.forEach(v => v.sort((a, b) => a - b))
  input = input.map(c => {
    let id = ('000000' + c[0]).slice(-6)
    id += ('000000' + (count[c[0]].indexOf(c[1]) + 1)).slice(-6)
    return id
  })
  console.log(input.join('\n'))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
