function main(input){
  var str = input.split('\n');
  var total = [];
  for(let i=0;i<str.length;i++){
    var str2 = str[i].split(' ');
    var int = [parseInt(str2[0]),parseInt(str2[1])]
    total.push(int);
  }
  var N = total[0][0];//県の数
  var M = total[0][1];//N個の件に存在する市の総数
  var prefuclist = [];
  var yearlist = [];
  for(let j=1;j<=M;j++){
    var prefuc = total[j][0]+'';
    var add0 = '0';
    var prefuc = add0.repeat(6-prefuc.length)+prefuc;
    prefuclist.push(prefuc);
  }
  var checkyear = [];
    for(let l=1;l<=M;l++){
      var sum = 1;
      for(let m=1;m<=M;m++){
        if(total[l][0] === total[m][0]){
          var diff = total[l][1]-total[m][1];
          if(diff >0){
            sum++;
          }//if(diff >0)
        }//if(total[l][0] === total[m][0])
      }//for(let m=1;m<=M;m++)
      checkyear.push(sum);
    }//for(let l=1;l<=M;l++)
  console.log(checkyear);
  for(let n=0;n<M;n++){
  	var year = checkyear[n]+'';
    var add0 = '0';
    var year = add0.repeat(6-year.length)+year;
    yearlist.push(year);
  }
  for(let o=0;o<M;o++){
    console.log(prefuclist[o]+yearlist[o]);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));