// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
if (!String.prototype.padStart) {
  String.prototype.padStart = function padStart(targetLength, padString) {
    targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;
    padString = String(typeof padString !== 'undefined' ? padString : ' ');
    if (this.length > targetLength) {
      return String(this);
    } else {
      targetLength = targetLength - this.length;
      if (targetLength > padString.length) {
        padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed
      }
      return padString.slice(0, targetLength) + String(this);
    }
  };
}
const Main = (input) => {
  // 入力値の整形
  input = input.split('\n');
  input.shift();
  const cities = input.map((line, index) => {
    const lineArray = line.split(' ');
    const ken = lineArray[0];
    const year = lineArray[1];
    return {
      index: index,
      ken: ken,
      year: year,
    };
  });

  const kenArray = [];
  cities
    .concat()
    .sort((a, b) => {
      return a.year - b.year;
    })
    .forEach((city) => {
      if (!kenArray[city.ken]) kenArray[city.ken] = [];
      kenArray[city.ken].push(city);
      cities[city.index].cityId =
        String(city.ken).padStart(6, '0') +
        String(kenArray[city.ken].length).padStart(6, '0');
    });

  cities.forEach((city) => {
    console.log(city.cityId);
  });
};

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));
/*