function zeroPadding(str) {
  return ('000000' + str).slice(-6)
}


function Main(input) {
  const data = input.trim().split('\n')
  const temp = data[0].split(' ').map(s => parseInt(s))
  const N = temp[0] // 県
  const M = temp[1] // 市

  const rest = data.slice(1).map(s => {
    return s.split(' ').map(x => parseInt(x))
  })

  var ans = {}
  rest.forEach((d, index) => {
    if(!ans[d[0]]) ans[d[0]] = []
    ans[d[0]].push({index: index, p: d[0], t: d[1], s: '' })
  })

  // console.log(ans)


  for(var i in ans) {
    ans[i] = ans[i].sort((a, b) => a.t - b.t)
  }

  var res = Array(M)
  for(var i in ans) {
    for(var j = 0; j < ans[i].length; ++j) {
      var d = ans[i][j]
      var str = zeroPadding(d.p) + zeroPadding((j+1).toString())
      res[d.index] = str
    }
  }

  var output = res.reduce((p, c) => p + '\n' + c)

  console.log(output)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));