const fs = require('fs'), util = require('util');
const readFile = util.promisify(fs.readFile).bind(util);
const zerofill = (str, n) => ('0'.repeat(n) + str).slice(-n);

const f1 = (async() => {
    const lines = (await readFile('/dev/stdin')).toString().split('\n');
    lines.reverse();
    const [N, M] = lines.pop().split(' ');
    const data = [];
    const _P = [];
    for (let i = 0; i < M; i++) {
        const [P_i, Y_i] = lines.pop().split(' ');
        data.push([P_i, Y_i, i]);
        _P.push(P_i);
    }
    const P = _P.sort().filter((item,i) => _P.indexOf(item) === i);
    const sortedData = data.concat().sort((a,b) => a[1] - b[1]);

    const result = [];
    for (let i = 0; i < N; i++) {
        const IDs = sortedData.filter(([p, _]) => p == P[i]).map(([P, Y, i], x) => {
            return [Y, zerofill(P, 6) + zerofill(x+1, 6), i];
        });
        for (const [Y, id, i] of IDs) {
            result[i] = id;
        }
    }
    console.log(result.join('\n'));
});

f1();
