if (!String.prototype.padStart) {
    String.prototype.padStart = function padStart(targetLength,padString) {
        targetLength = targetLength>>0; //truncate if number or convert non-number to 0;
        padString = String((typeof padString !== 'undefined' ? padString : ' '));
        if (this.length > targetLength) {
            return String(this);
        }
        else {
            targetLength = targetLength-this.length;
            if (targetLength > padString.length) {
                padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
            }
            return padString.slice(0,targetLength) + String(this);
        }
    };
}


function Main(input) {
  const data = input.split("\n")
  const a = data.shift().split(" ")
  const N = a[0]
    const M = a[1]
  const pref = []
  data.forEach( (d, i) => {
    if (d.length === 0) { return; }
    const x = d.split(" ")
      const I = x[0]
      const Y = x[1]
    var P = pref[I]
    if (P === undefined) {
      pref[I] = [[i,Y]]
    } else {
      P.push([i,Y])
    }
  })
  const r = [];

  pref.forEach( (p,pi) => {
    if (!Array.isArray(p)) { return;}
    p.sort( (a, b) => {
      const a1 = parseInt(a[1]), b1 = parseInt(b[1])
      return a1 > b1 ? 1 : a1 === b1 ? 0 : -1
    })
    p.forEach( (m, mi) => {
      r[m[0]] = ("" + pi).padStart(6, "0") + ("" + (mi + 1)).padStart(6, "0")
    })
  });

  console.log(r.join("\n"))


}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 