"use strict";

function binarySearch(arr, val) {
  let start = 0;
  let end = arr.length - 1;

  while (start <= end) {
    let mid = Math.floor((start + end) / 2);

    if (arr[mid] === val) {
      return mid;
    }
    if (val < arr[mid]) {
      end = mid - 1;
    } else {
      start = mid + 1;
    }
  }
  return -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"));
