function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],4)[0];
  var M = myconv(input[0],4)[1];
  input.shift();
  var tmp = JSON.parse(JSON.stringify(input));
  var list = {};
  tmp.sort(function(a,b){
  	var pa = myconv(a,4)[0];
    var ya = myconv(a,4)[1];
    var pb = myconv(b,4)[0];
    var yb = myconv(b,4)[1];
    if(pa == pb){
       return ya-yb;
       }else{
       return pa-pb;
       }
  });
  
  var maeP = "";
  var yCount = 1;
  for(var i = 0; i < tmp.length; i++){
    var p = myconv(tmp[i],2)[0];
    if(maeP != p){
       yCount = 1;
       maeP = p;
    }else{
       yCount++;
    }
    
    var setP = "";
    for(var j = 0; j < 6-p.length; j++){
      setP += "0";
    }
    setP += p;
    
    var setY = "";
    for(var j = 0; j < 6-yCount.toString().length; j++){
      setY += "0";
    }
    setY += yCount;
    list[tmp[i]] = setP + setY;
  }
  
  var output = [];
  for(var i = 0; i < input.length; i++){
    output.push(list[input[i]]);
  }
  myout(output.join("\n"));
}

Main(myin());
