object Main {
  
  def main(args:Array[String]):Unit={
    var NM = readLine.split(" ")
    for(i<-0 until NM(1).toInt){
      var temp = readLine.split(" ")
      println(cityNumber(temp(0),temp(1)))
    }
  }
  
  def cityNumber(ken:String,shi:String):String={
    var lenK = ken.length
    var lenS = shi.length
    var tempK = ken
    var tempS = shi
    var diffK = 6-lenK
    var diffS = 6-lenS
    for(i<-0 until diffK){
      tempK=0.toString + tempK
    }
    for(i<-0 until (6-lenS)){
      tempS=0.toString + tempS
    }
    return tempK+tempS
  }
  
}