"use strict";

function binarySearch(ar, el, compare_fn = (a,b) => a-b) {
  var m = 0;
  var n = ar.length - 1;
  while (m <= n) {
      var k = (n + m) >> 1;
      var cmp = compare_fn(el, ar[k]);
      if (cmp > 0) {
          m = k + 1;
      } else if(cmp < 0) {
          n = k - 1;
      } else {
          return k;
      }
  }
  return -m - 1;
}

function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  const N = Number(inputs[0].split(" ")[0]);
  const M = Number(inputs[0].split(" ")[1]);
  
  const P = [];
  const Y = [];
  const ID = [];

  for (let i = 0; i < M; i++) {
    const inputLine = inputs[1+i].split(" ");
    const Pi = inputLine[0];
    const Yi = inputLine[1];
    P.push(Pi);
    Y.push(Yi);
  }

  const mapArr = {};

  for (let i = 0; i < P.length; i++) {
    if (mapArr[P[i]]) {
      mapArr[P[i]].push(Y[i]);
    } else {
      mapArr[P[i]] = [Y[i]];
    }
  }

  for (let Pi in mapArr) {
    mapArr[Pi] = mapArr[Pi].sort((a,b) => a - b);
  }

  let result = "";
  for (let i = 0; i < P.length; i++) {
    let firstHalf = "" + P[i];
    while (firstHalf.length < 6) {
      firstHalf = "0" + firstHalf;
    }

    let secondHalf = "" + (binarySearch(mapArr[P[i]], Y[i]) + 1);
    while (secondHalf.length < 6) {
      secondHalf = "0" + secondHalf;
    }

    result = result + firstHalf + secondHalf + "\n";
  }

  console.log(result);
}

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