import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	int m = read.to!int;
	
	S[] as;
	foreach(i; 0 .. m){
		as ~= S(i, read.to!int, read.to!long);
	}
	
	as.sort!"a.y<b.y"();
	
	int[][int] xm;
	foreach(a; as){
		if(a.p !in xm) xm[a.p] = [];
		xm[a.p] ~= a.id;
	}
	
	string[] ans = new string[](m);
	int[] ps = xm.keys;
	foreach(p; ps){
		int[] ids = xm[p];
		foreach(j, id; ids){
			ans[id] = "%06d".format(p) ~ "%06d".format(j + 1);
		}
	}
	
	foreach(an; ans) an.writeln;
}

struct S{
	int id;
	int p;
	long y;
}
