stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <vector>

#include <set>

#include <iomanip>

using namespace std;



inline int POS(int k,int value);



const int MAXN = 2e5+10;



struct P {

    int x,y;

} H[MAXN];



vector<int> G[MAXN];



set<int> s;

set<int>::iterator it;



int main()

{

    int N,M;

	cin>>N>>M;

	

    for(int i=1; i<=M; i++) {

        int x,y;

		cin>>x>>y;

		

        H[i].x = x;

		H[i].y = y;

		

        s.insert(x);

		G[x].push_back(y);

    }

    

    for(int i=1; i<=N; i++) {

        sort(G[i].begin(), G[i].end());

    }

    

    for(int i=1; i<=M; i++) {

        cout<<setw(6)<<setfill('0')<<H[i].x

			<<setw(6)<<setfill('0')<<POS(H[i].x, H[i].y)+1<<endl;

    }

    

    return 0;

}



inline int POS(int k,int value) {

    for(int left = 0, len = G[k].size(), right = len - 1; left <= right ;) {

        int mid = left + (right - left) / 2;

        if(G[k][mid] == value) {

        	return mid;

		} else if(G[k][mid] > value) {

        	right = mid;

		} else {

        	left = mid + 1;

		}

    }

    return -1;

}

// Faster C++ solution for the same problem (measured speedup: 6.538347909232024x):
#include<bits/stdc++.h>

using namespace std;



struct data2

{

	int p, y, nn, num;

}c[100010];



bool cmp(data2 u, data2 v)

{

	if (u.p == v.p) return u.y<v.y;

	return u.p < v.p; 

}

bool cmp2(data2 u, data2 v)

{

	return u.nn < v.nn; 

}



int ans[100010];



int main()

{

	int n, m;

	scanf("%d%d", &n, &m);

	for (int i = 1; i <= m; ++i)

		scanf("%d%d", &c[i].p, &c[i].y), c[i].nn = i;

	sort(c+1, c+m+1, cmp);

	for (int i=1, j=1; i <= m; i=j)

	{

		int k = 0;

		while (j <= m && c[j].p == c[i].p) 

		{

			++k;

			c[j].num = k;

			++j; 

		}

	}

	sort(c+1, c+m+1, cmp2);

	for (int i = 1; i <= m; ++i)

		printf("%06d%06d\n", c[i].p, c[i].num);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define  ll  long long

#define  pi  pair<int,int>

#define  pb  push_back

#define  F   first

#define  S   second

const int N=1e5+3;

vector<int>v[N];

string s,p,t,ans[N];

map<pi,int>mp;

int main()

{

    ft

    int i,j,n,k,m,l,r;

    cin>>n>>m;

    for(i=0; i<m; i++)

    {

        cin>>l>>r;

        v[l].pb(r);

        mp[{l,r}]=i+1;

    }

    for(i=1; i<=n; i++)

    {

        sort(v[i].begin(),v[i].end());

        int sz=v[i].size();

        if(sz>0)

        {

            for(int z=0; z<sz; z++)

            {

                s.clear();

                p.clear();

                l=0;

                r=i;

                while(r!=0)

                {

                    s+=((r%10)+48);

                    r/=10;

                    l++;

                }

                for(k=0; k<(6-l); k++)

                {

                    p+='0';

                }

                reverse(s.begin(),s.end());

                t=p+s;

                l=0;

                r=z+1;

                s.clear();

                p.clear();

                while(r!=0)

                {

                    s+=((r%10)+48);

                    r/=10;

                    l++;

                }

                for(k=0; k<(6-l); k++)

                {

                    p+='0';

                }

                reverse(s.begin(),s.end());

                int cc=mp[{i,v[i][z]}];

                ans[cc]=t+p+s;

            }

        }

    }

    for(i=1;i<=m;i++)

    {

        cout<<ans[i]<<"\n";

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 7.403845919575527x):
#include<bits/stdc++.h>

using namespace std;



struct data2

{

	int p, y, nn, num;

}c[100010];



bool cmp(data2 u, data2 v)

{

	if (u.p == v.p) return u.y<v.y;

	return u.p < v.p; 

}

bool cmp2(data2 u, data2 v)

{

	return u.nn < v.nn; 

}



int ans[100010];



int main()

{

	int n, m;

	scanf("%d%d", &n, &m);

	for (int i = 1; i <= m; ++i)

		scanf("%d%d", &c[i].p, &c[i].y), c[i].nn = i;

	sort(c+1, c+m+1, cmp);

	for (int i=1, j=1; i <= m; i=j)

	{

		int k = 0;

		while (j <= m && c[j].p == c[i].p) 

		{

			++k;

			c[j].num = k;

			++j; 

		}

	}

	sort(c+1, c+m+1, cmp2);

	for (int i = 1; i <= m; ++i)

		printf("%06d%06d\n", c[i].p, c[i].num);

	return 0;

}
// Slower C++ solution:
// https://atcoder.jp/contests/abc113/tasks/abc113_c

#include <algorithm>

#include <climits>

#include <iomanip>

#include <iostream>

#include <string>

#include <tuple>

#include <vector>

using namespace std;



typedef long long ll;

const int INF = 1e9;

const int MOD = 1e9 + 7;

const ll LINF = 1e18;



#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

#define REP(i, n) for (int i = 0; i < (n); ++i)

#define REPR(i, n) for (int i = n; i >= 0; i--)

#define FOREACH(x, a) for (auto &(x) : (a))



// No、市、年、順位

typedef tuple<int, int, int, int> mytuple;



// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



// 年でソート（0番目から数えて2番目）

bool mycompare(const mytuple &lhs, const mytuple &rhs) {

    return get<2>(lhs) < get<2>(rhs);

}



int main() {

    int n, m, t1, t2;

    ios::sync_with_stdio(false);

    cin.tie(0);

    cin >> n >> m;

    mytuple tu[m];



    REP(i, m) {

        cin >> t1 >> t2;

        tu[i] = make_tuple(i, t1, t2, 0);

    }

    //年でソート

    sort(tu, tu + m, mycompare);



    // 市の出現回数をメモ

    int cnt[n + 1];

    REP(i, n + 1) cnt[i] = 0;

    REP(i, m) {

        int ct = get<1>(tu[i]);

        cnt[ct]++;

        tu[i] = make_tuple(get<0>(tu[i]), get<1>(tu[i]), get<2>(tu[i]), cnt[ct]);

    }

    // 入力順でソート

    sort(tu, tu + m);

    REP(i, m) {

        cout << setw(6) << std::setfill('0') << (get<1>(tu[i]));

        cout << setw(6) << std::setfill('0') << (get<3>(tu[i])) << endl;

    }



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.2223701645210205x):
// https://atcoder.jp/contests/abc113/tasks/abc113_c

#include <algorithm>

#include <cstdio>

#include <tuple>

using namespace std;



typedef long long ll;

const int INF = 1e9;

const int MOD = 1e9 + 7;

const ll LINF = 1e18;



#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

#define REP(i, n) for (int i = 0; i < (n); ++i)

#define REPR(i, n) for (int i = n; i >= 0; i--)

#define FOREACH(x, a) for (auto &(x) : (a))



// No、市、年、順位

typedef tuple<int, int, int, int> mytuple;



// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }



// 年でソート（0番目から数えて2番目）

bool mycompare(const mytuple &lhs, const mytuple &rhs) {

    return get<2>(lhs) < get<2>(rhs);

}



int main() {

    int n, m, t1, t2;

    scanf("%d%d", &n, &m);

    mytuple tu[m];



    REP(i, m) {

        scanf("%d%d", &t1, &t2);

        tu[i] = make_tuple(i, t1, t2, 0);

    }

    // 年でソート

    sort(tu, tu + m, mycompare);



    // 市の出現回数をメモ

    int cnt[n + 1];

    REP(i, n + 1) cnt[i] = 0;

    REP(i, m) {

        int city = get<1>(tu[i]);

        cnt[city]++;

        tu[i] =

            make_tuple(get<0>(tu[i]), get<1>(tu[i]), get<2>(tu[i]), cnt[city]);

    }

    // 入力順でソート

    sort(tu, tu + m);

    REP(i, m) { printf("%06d%06d\n", get<1>(tu[i]), get<3>(tu[i])); }



    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<map>

using namespace std;

const int maxn = 1e5 + 1;

struct node{

	int p,y;

	int num;

	int sub;

}no;

vector<node> v[maxn];

bool cmp(node a,node b){

	return a.y<b.y;

}

int main(){

	int n,m,p,y;

	cin>>n>>m;

	map<int,node> Map;

	for(int i=1;i<=m;i++){

		cin>>p>>y;

		no.p=p;no.y=y;

		no.sub=i;

		Map[i]=no;

		v[p].push_back(no);

	}

	for(int i=1;i<=n;i++){

		sort(v[i].begin(),v[i].end(),cmp);

		for (int j=0;j<v[i].size();j++){

        	Map[v[i][j].sub].num=j+1;

    	}

	}

	for(int i=1;i<=m;i++){

		printf("%06d%06d\n",Map[i].p,Map[i].num);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.538435534297938x):
#include <iostream>

#include <algorithm>

#include <string>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

const int MAX=1e5+5;

struct city

{

	int P;

	int Y;

	int num;

	int x;

}c[MAX];

bool cmp1(city a,city b)

{

	if(a.P==b.P)

		return a.Y<b.Y;

	else

		return a.P<b.P;

}

bool cmp2(city a,city b)

{

	return a.num<b.num;

}

int main(int argc, char *argv[])

{

	int n,m;

	cin>>n>>m;

	for(int i=0;i<m;i++)

		{cin>>c[i].P>>c[i].Y;c[i].num=i+1;}

	sort(c,c+m,cmp1);

	int x=c[1].P;

	int y=1;

	for(int i=0;i<m;i++)

	{

		if(x!=c[i].P)

		{

			x=c[i].P;

			y=1;

		}

		c[i].x=y;

		y++;

	}

	sort(c,c+m,cmp2);

	for(int i=0;i<m;i++)

		printf("%06d%06d\n",c[i].P,c[i].x);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <cmath>

#include <algorithm>

#include <cstdio>

using namespace std;

struct node

{

	int num;

	int xian;

	int shi;

	int time;

}d[100005];

bool cmp1(node a,node b)

{

	if(a.xian<b.xian)return true;

	else if(a.xian==b.xian)

	{

		if(a.time<b.time)return true;

		else return false;

	}

	return false;

	

}

bool cmp2(node a,node b)

{

	return a.num<b.num;

}

int main()

{

	int n,m;

	cin>>n>>m;

	for(int i=1;i<=m;i++)

	{

		cin>>d[i].xian>>d[i].time;

		d[i].num=i;

	}

	sort(d+1,d+m+1,cmp1);

	int cnt=1;

	for(int i=1;i<=m;i++)

	{

		if(i!=1&&d[i].xian!=d[i-1].xian)cnt=1;

		d[i].shi=cnt;

		cnt++;

	}

	sort(d+1,d+m+1,cmp2);

	for(int i=1;i<=m;i++)

	{

		printf("%06d%06d\n",d[i].xian,d[i].shi);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.611496057513258x):
#include<cstdio>

#include<algorithm>

using namespace std;

struct ss{

	int rank;

    int p;

    int y;

}a[100005];

int cmp(ss x,ss y){

    if(x.p!=y.p) return x.p<y.p;

    else return x.y<y.y;

}

int main()

{

    int n ,m;

    scanf("%d%d",&n,&m);

    int b[100005];

    for(int i=0;i<m;i++){

    	a[i].rank=i;

        scanf("%d%d",&a[i].p,&a[i].y); 	

        b[i]=a[i].p;

	}

    sort(a,a+m,cmp);

    int f=a[0].p,flag=1;

    int x[100005];

    

    for(int i=0;i<m;i++){

    	if(a[i].p!=f) {flag=1;f=a[i].p;}

    	x[a[i].rank]=flag++;

	}

    // for(int i=0;i<m;i++)

    //    cout<< a[i].rank<<" "<<a[i].p<<" " <<a[i].y<<endl;

    for(int i=0;i<m;i++)

        printf("%06d%06d\n",b[i],x[i]);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

 

struct node{

	int p,y;

}x[100005];

 

bool cmp(node a,node b)

{

	if(a.p==b.p) return a.y<b.y;

	return a.p<b.p;

}

 

int a[100005],b[100005];

 

map<pair<int , int >,int >m1;

 

int main()

{

	int n,m;

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&a[i],&b[i]);

		x[i].p=a[i];

		x[i].y=b[i];	

	}

	sort(x+1,x+m+1,cmp);

	int t=0,tt=1;

	for(int i=1;i<=m;i++)

	{

		if(x[i].p==t){

			m1[make_pair(x[i].p,x[i].y)]=tt;

			tt++;

		}

		else{

			m1[make_pair(x[i].p,x[i].y)]=1;

			tt=2;

			t=x[i].p;

		}

	}

	for(int i=1;i<=m;i++)

	{		

		printf("%06d%06d\n",a[i],m1[make_pair(a[i],b[i])]);

	}

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 4.620451063385219x):
#include<cstdio>

#include<algorithm>

using namespace std;

struct ss{

	int rank;

    int p;

    int y;

}a[100005];

int cmp(ss x,ss y){

    if(x.p!=y.p) return x.p<y.p;

    else return x.y<y.y;

}

int main()

{

    int n ,m;

    scanf("%d%d",&n,&m);

    int b[100005];

    for(int i=0;i<m;i++){

    	a[i].rank=i;

        scanf("%d%d",&a[i].p,&a[i].y); 	

        b[i]=a[i].p;

	}

    sort(a,a+m,cmp);

    int f=a[0].p,flag=1;

    int x[100005];

    

    for(int i=0;i<m;i++){

    	if(a[i].p!=f) {flag=1;f=a[i].p;}

    	x[a[i].rank]=flag++;

	}

    // for(int i=0;i<m;i++)

    //    cout<< a[i].rank<<" "<<a[i].p<<" " <<a[i].y<<endl;

    for(int i=0;i<m;i++)

        printf("%06d%06d\n",b[i],x[i]);

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<map>

using namespace std;

const int maxn = 1e5 + 1;

struct node{

	int p,y;

	int num;

	int sub;

}no;

vector<node> v[maxn];

bool cmp(node a,node b){

	return a.y<b.y;

}

int main(){

	int n,m,p,y;

	cin>>n>>m;

	map<int,node> Map;

	for(int i=1;i<=m;i++){

		cin>>p>>y;

		no.p=p;no.y=y;

		no.sub=i;

		Map[i]=no;

		v[p].push_back(no);

	}

	for(int i=1;i<=n;i++){

		sort(v[i].begin(),v[i].end(),cmp);

		for (int j=0;j<v[i].size();j++){

        	Map[v[i][j].sub].num=j+1;

    	}

	}

	for(int i=1;i<=m;i++){

		printf("%06d%06d\n",Map[i].p,Map[i].num);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 16.313925247591243x):
#include<cstdio>

#include<algorithm>

using namespace std;

struct ss{

	int rank;

    int p;

    int y;

}a[100005];

int cmp(ss x,ss y){

    if(x.p!=y.p) return x.p<y.p;

    else return x.y<y.y;

}

int main()

{

    int n ,m;

    scanf("%d%d",&n,&m);

    int b[100005];

    for(int i=0;i<m;i++){

    	a[i].rank=i;

        scanf("%d%d",&a[i].p,&a[i].y); 	

        b[i]=a[i].p;

	}

    sort(a,a+m,cmp);

    int f=a[0].p,flag=1;

    int x[100005];

    

    for(int i=0;i<m;i++){

    	if(a[i].p!=f) {flag=1;f=a[i].p;}

    	x[a[i].rank]=flag++;

	}

    // for(int i=0;i<m;i++)

    //    cout<< a[i].rank<<" "<<a[i].p<<" " <<a[i].y<<endl;

    for(int i=0;i<m;i++)

        printf("%06d%06d\n",b[i],x[i]);

    return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <string>

#include <cstdio>

#include <cstring>

#include <cmath>

using namespace std;

const int MAX=1e5+5;

struct city

{

	int P;

	int Y;

	int num;

	int x;

}c[MAX];

bool cmp1(city a,city b)

{

	if(a.P==b.P)

		return a.Y<b.Y;

	else

		return a.P<b.P;

}

bool cmp2(city a,city b)

{

	return a.num<b.num;

}

int main(int argc, char *argv[])

{

	int n,m;

	cin>>n>>m;

	for(int i=0;i<m;i++)

		{cin>>c[i].P>>c[i].Y;c[i].num=i+1;}

	sort(c,c+m,cmp1);

	int x=c[1].P;

	int y=1;

	for(int i=0;i<m;i++)

	{

		if(x!=c[i].P)

		{

			x=c[i].P;

			y=1;

		}

		c[i].x=y;

		y++;

	}

	sort(c,c+m,cmp2);

	for(int i=0;i<m;i++)

		printf("%06d%06d\n",c[i].P,c[i].x);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.610491017700028x):
#include<cstdio>

#include<algorithm>

using namespace std;

struct ss{

	int rank;

    int p;

    int y;

}a[100005];

int cmp(ss x,ss y){

    if(x.p!=y.p) return x.p<y.p;

    else return x.y<y.y;

}

int main()

{

    int n ,m;

    scanf("%d%d",&n,&m);

    int b[100005];

    for(int i=0;i<m;i++){

    	a[i].rank=i;

        scanf("%d%d",&a[i].p,&a[i].y); 	

        b[i]=a[i].p;

	}

    sort(a,a+m,cmp);

    int f=a[0].p,flag=1;

    int x[100005];

    

    for(int i=0;i<m;i++){

    	if(a[i].p!=f) {flag=1;f=a[i].p;}

    	x[a[i].rank]=flag++;

	}

    // for(int i=0;i<m;i++)

    //    cout<< a[i].rank<<" "<<a[i].p<<" " <<a[i].y<<endl;

    for(int i=0;i<m;i++)

        printf("%06d%06d\n",b[i],x[i]);

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<map>

using namespace std;

const int maxn = 1e5 + 1;

struct node{

	int p,y;

	int num;

	int sub;

}no;

vector<node> v[maxn];

bool cmp(node a,node b){

	return a.y<b.y;

}

int main(){

	int n,m,p,y;

	cin>>n>>m;

	map<int,node> Map;

	for(int i=1;i<=m;i++){

		cin>>p>>y;

		no.p=p;no.y=y;

		no.sub=i;

		Map[i]=no;

		v[p].push_back(no);

	}

	for(int i=1;i<=n;i++){

		sort(v[i].begin(),v[i].end(),cmp);

		for (int j=0;j<v[i].size();j++){

        	Map[v[i][j].sub].num=j+1;

    	}

	}

	for(int i=1;i<=m;i++){

		printf("%06d%06d\n",Map[i].p,Map[i].num);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.821199785038574x):
#include <cstdio>

#include <cstdlib>



typedef struct {

    int idx;

    int per;

    int year;

    char id[16];

} City;



int compCity(const void* aa, const void* bb) {

    City* a = (City*)aa;

    City* b = (City*)bb;



    if (a->per < b->per) return -1;

    else if (a->per > b->per) return 1;

    else if (a->year < b->year) return -1;

    return 1;

}



int compIdx(const void* aa, const void* bb) {

    City* a = (City*)aa;

    City* b = (City*)bb;



    if (a->idx < b->idx) return -1;

    return 1;

}



int main() {

    int N = 0, M = 0;

    scanf("%d %d", &N, &M);

    City *city = new City[M]();

    for (int i = 0; i < M; i++) {

        city[i].idx = i;

        scanf("%d %d", &(city[i].per), &(city[i].year));

    }



    qsort(city, M, sizeof(City), compCity);



    for (int i = 0, j = 1, p = city[0].per; i < M; i++) {

        if (p != city[i].per) {

            j = 1;

            p = city[i].per;

        }

        sprintf(city[i].id, "%06d%06d", p, j++);

    }



    qsort(city, M, sizeof(City), compIdx);



    for (int i = 0; i < M; i++) {

        printf("%s\n", city[i].id);

    }



    delete[] city;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector> 

#include<map>

using namespace std;

const int M=1e5+5;

struct node{

	int p,y;

	int k,num;

}q;

bool comp(node a,node b){

	return a.y<b.y;

}

vector<node> a[M];

map<int,node> Map;

int main(){

    int n,m;

    cin>>n>>m;

    for(int i=1;i<=m;i++){

    	int p,y;

    	cin>>p>>y;

    	q.p=p; q.y=y;

    	q.k=i;

    	Map[i]=q;

    	a[p].push_back(q);

	}

	for(int i=1;i<=n;i++){

		sort(a[i].begin(),a[i].end(),comp);

		for(int j=0;j<a[i].size();j++)

			Map[a[i][j].k].num=j+1;	

	}

	for(int i=1;i<=m;i++)

		printf("%06d%06d\n",Map[i].p,Map[i].num);

}

// Faster C++ solution for the same problem (measured speedup: 3.8127627569445433x):
#include <cstdio>

#include <cstdlib>



typedef struct {

    int idx;

    int per;

    int year;

    char id[16];

} City;



int compCity(const void* aa, const void* bb) {

    City* a = (City*)aa;

    City* b = (City*)bb;



    if (a->per < b->per) return -1;

    else if (a->per > b->per) return 1;

    else if (a->year < b->year) return -1;

    return 1;

}



int compIdx(const void* aa, const void* bb) {

    City* a = (City*)aa;

    City* b = (City*)bb;



    if (a->idx < b->idx) return -1;

    return 1;

}



int main() {

    int N = 0, M = 0;

    scanf("%d %d", &N, &M);

    City *city = new City[M]();

    for (int i = 0; i < M; i++) {

        city[i].idx = i;

        scanf("%d %d", &(city[i].per), &(city[i].year));

    }



    qsort(city, M, sizeof(City), compCity);



    for (int i = 0, j = 1, p = city[0].per; i < M; i++) {

        if (p != city[i].per) {

            j = 1;

            p = city[i].per;

        }

        sprintf(city[i].id, "%06d%06d", p, j++);

    }



    qsort(city, M, sizeof(City), compIdx);



    for (int i = 0; i < M; i++) {

        printf("%s\n", city[i].id);

    }



    delete[] city;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector>

#include<map>

using namespace std;

const int maxn = 1e5 + 1;

struct node{

	int p,y;

	int num;

	int sub;

}no;

vector<node> v[maxn];

bool cmp(node a,node b){

	return a.y<b.y;

}

int main(){

	int n,m,p,y;

	cin>>n>>m;

	map<int,node> Map;

	for(int i=1;i<=m;i++){

		cin>>p>>y;

		no.p=p;no.y=y;

		no.sub=i;

		Map[i]=no;

		v[p].push_back(no);

	}

	for(int i=1;i<=n;i++){

		sort(v[i].begin(),v[i].end(),cmp);

		for (int j=0;j<v[i].size();j++){

        	Map[v[i][j].sub].num=j+1;

    	}

	}

	for(int i=1;i<=m;i++){

		printf("%06d%06d\n",Map[i].p,Map[i].num);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4148656439359217x):
#include<cstdio>

#include<iostream>

#include<algorithm>



using namespace std;



struct temp

{

    int rank;

    int p;

    int y;

}a[100005];



int cmp(temp x, temp y)

{

    if(x.p != y.p)

        return x.p<y.p;

    else

        return x.y<y.y;

}



int main()

{

    int n,m;

    while(cin >> n >> m)

    {

        int b[100005];

    for(int i = 0; i< m; i++)

    {

        a[i].rank = i;

        cin >> a[i].p >> a[i].y;

        b[i] = a[i].p;

    }



    sort(a,a+m,cmp);

    int f = a[0].p,flag = 1;

    int x[100005];



    for(int i = 0; i < m; i++)

    {

        if(a[i].p != f)

        {

            flag = 1;

            f = a[i].p;

        }

        x[a[i].rank] = flag++;

    }



    for(int i = 0; i < m; i++)

        printf("%06d%06d\n",b[i],x[i]);



    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<vector> 

#include<map>

using namespace std;

const int M=1e5+5;

struct node{

	int p,y;

	int k,num;

}q;

bool comp(node a,node b){

	return a.y<b.y;

}

vector<node> a[M];

map<int,node> Map;

int main(){

    int n,m;

    cin>>n>>m;

    for(int i=1;i<=m;i++){

    	int p,y;

    	cin>>p>>y;

    	q.p=p; q.y=y;

    	q.k=i;

    	Map[i]=q;

    	a[p].push_back(q);

	}

	for(int i=1;i<=n;i++){

		sort(a[i].begin(),a[i].end(),comp);

		for(int j=0;j<a[i].size();j++)

			Map[a[i][j].k].num=j+1;	

	}

	for(int i=1;i<=m;i++)

		printf("%06d%06d\n",Map[i].p,Map[i].num);

}

// Faster C++ solution for the same problem (measured speedup: 3.4073257823751537x):
#include<cstdio>

#include<iostream>

#include<algorithm>



using namespace std;



struct temp

{

    int rank;

    int p;

    int y;

}a[100005];



int cmp(temp x, temp y)

{

    if(x.p != y.p)

        return x.p<y.p;

    else

        return x.y<y.y;

}



int main()

{

    int n,m;

    while(cin >> n >> m)

    {

        int b[100005];

    for(int i = 0; i< m; i++)

    {

        a[i].rank = i;

        cin >> a[i].p >> a[i].y;

        b[i] = a[i].p;

    }



    sort(a,a+m,cmp);

    int f = a[0].p,flag = 1;

    int x[100005];



    for(int i = 0; i < m; i++)

    {

        if(a[i].p != f)

        {

            flag = 1;

            f = a[i].p;

        }

        x[a[i].rank] = flag++;

    }



    for(int i = 0; i < m; i++)

        printf("%06d%06d\n",b[i],x[i]);



    }

    return 0;

}