"use strict";

    
const make6digit = num => {
    num = String(num);
    let digit = num.split("").length;
    
    if(digit < 6) {
        for(let i=0; i<6-digit; i++) {
            num = "0" + num;
        }
    }
    
    return num;
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    const cities = arg.slice(1, M + 1);
    let data = [];
    
    for(let i in cities) {
        let tempPrefecture = parseInt(cities[i].split(" ")[0]);
        let tempBirth      = parseInt(cities[i].split(" ")[1]);
        
        data.push({
            prefecture: tempPrefecture,
            birth:      tempBirth,
            index:      i
        })
    }
    
    data.sort((a,b) => {
        if(a.prefecture < b.prefecture) {
            return -1;
        }
        
        if(a.prefecture > b.prefecture) {
            return 1;
        }
        
        if(a.birth < b.birth) {
            return -1;
        }
        
        if(a.birth > b.birth) {
            return 1;
        }
    });
    
    let num = 1;
    
    for(let i in data) {
        if(data[i-1]) {
            if(data[i].prefecture !== data[i-1].prefecture) {
                num = 1;
            }
        }
        
        let firstHalf = make6digit(data[i].prefecture);
        let lastHalf  = make6digit(num);
        
        const id = firstHalf + lastHalf;
        
        data[i].id = id;
        
        num++;
    }
    
    data.sort((a,b)=>a.index - b.index);
    
    for(let i in data) {
        console.log(data[i].id);   
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
