#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

#pragma GCC target("avx,avx2")
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
struct Edge {
	int s;
	int dst;
	long long int cost;
};
using Graph=vector<vector<Edge>>;



const int mod = 1000000007;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const long long  int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}

//mod が素数の場合のみ　違う場合はextend euclid を用いる。
Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}


vector<long long int> dfs(int start, Graph&g) {
	vector<long long int>depths;

	depths.clear();
	depths.resize(g.size());
	fill(depths.begin(),depths.end(),1ll<<60);
	depths[start]=0;
	priority_queue<pair<long long int,int>>que;
	que.emplace(0,start);
	while (!que.empty()) {
		auto p=que.top();
		que.pop();
		long long int now_cost=-p.first;
		long long int now=p.second;
		if(depths[now]!=now_cost)continue;
		else {
			for (auto e : g[now]) {
				long long next_cost=now_cost+e.cost;
				if (depths[e.dst] > next_cost) {
					depths[e.dst]=next_cost;
					que.push(make_pair(-next_cost,e.dst));
				}
			}
		}
	}
	return depths;
}

vector<Mod>get_nums(int start, const Graph&g, vector<long long int>&depths) {
	vector<Mod>nums(g.size());
	nums[start]=1;
	vector<pair<long long int,int>>vv(g.size());
	for (int i = 0; i < g.size(); ++i) {
		vv[i]=make_pair(depths[i],i);
	}
	sort(vv.begin(),vv.end());
	for (int i = 0; i < vv.size(); ++i) {
		int now=vv[i].second;
		for (auto e : g[now]) {
			if(depths[now]+e.cost==depths[e.dst])nums[e.dst]+=nums[now];
		}
	}
	return nums;
}

bool check(vector<int>&anss, string st) {
	for (int i = 0; i < st.size(); ++i) {
		int l=(i+st.size()-1)%int(st.size());
		int r=(i+1)%int(st.size());
		if ((st[i] == 'o')^anss[i]) {
			if(anss[l]==anss[r])return false;
		}
		else {
			if(anss[l]!=anss[r])return false;
		}
	}
	return true;
}

vector<int>solve(vector<int>&anss, string st) {
	for (int i = 2; i < st.size(); ++i) {
		if ((st[i-1] == 'o')^anss[i-1]) {

			anss[i] = 1 - anss[i - 2];
		}
		else {

			anss[i] = anss[i - 2];

		}
	}
	if (check(anss, st)) {
		return anss;
	}
	else {
		vector<int>v;
		return v;
	}
}

int main(){
	int N,M;cin>>N>>M;
	vector<vector<pair<int,int>>>v(N);
	for (int i = 0; i < M; ++i) {
		int a, b;cin>>a>>b;a--;
		v[a].push_back(make_pair(b,i));
	}
	for (int i = 0; i < N; ++i) {
		sort(v[i].begin(),v[i].end());
	}
	vector<pair<int,int>>anss(M);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j< v[i].size(); ++j) {
			anss[v[i][j].second]=make_pair(i+1,j+1);
		}
	}
	for (int i = 0; i < M; ++i) {
		printf("%06d%06d",anss[i].first,anss[i].second);
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 7808