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

#include <vector>

#include <algorithm>

#include <climits>

#include <iomanip>



using namespace std;



vector <int> ans[100001];



int main(){

    int N, M;

    cin >> N >> M;

    vector <int> P, Y;

    

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

        int sub;

        cin >> sub;

        P.push_back(sub);

        cin >> sub;

        Y.push_back(sub);

        ans[P[i]].push_back(Y[i]);

    }



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

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

    }

    

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

        cout << setfill('0') << setw(6) << P[i];

        cout << setfill('0') << setw(6) << int(lower_bound(ans[P[i]].begin(), ans[P[i]].end(), Y[i]) - ans[P[i]].begin()) + 1 << "\n";

    }

}

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

#include <vector>

#include <algorithm>

#include <cmath>

#include <queue>

#include <string>

#include <map>

#include <set>

#include <stack>

#include <tuple>

#include <deque>

#include <numeric>

#include <bitset>

#include <iomanip>

#include <cassert>

#include <chrono>

#include <random>

#include <limits>

#include <iterator>

#include <functional>

#include <sstream>

#include <complex>

using namespace std;



typedef long long ll;

typedef uint64_t ull;

typedef pair<int, int> P;

constexpr double PI = 3.1415926535897932;   // acos(-1)

constexpr double EPS = 1e-9;

constexpr int INF = 1001001001;

constexpr int mod = 1000000007;

// constexpr int mod = 998244353;



#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int n, m;

    cin >> n >> m;

    vector<vector<P>> input(n + 1);

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

        int p, y;

        cin >> p >> y;

        input[p].push_back(P(y, i));

    }

    for(int i = 1; i <= n; ++i) sort(input[i].begin(), input[i].end());

    vector<ll> ans(m, 0);

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

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

        for(int j = 0; j < sz; ++j){

            int y = input[i][j].first, id = input[i][j].second;

            ans[id] += (ll)i * 1000000;

            ans[id] += j + 1;

        }

    }

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

        cout << setfill('0') << right << setw(12);

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

    }

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

#include <string>

#include <vector>

#include <algorithm>



using namespace std;



int main(){

  int N, M;

  cin >> N >> M;

  vector<pair<int, int> > P[100010];

  string s[100010];

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

    int p, y;

    cin >> p >> y;

    P[p].emplace_back(make_pair(y,i));

  }

  for(int i=1; i<=N; i++) sort(P[i].begin(), P[i].end());

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

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

      for(int k=0; k<6-to_string(i).size(); k++) s[P[i][j].second]+='0';

      s[P[i][j].second]+=to_string(i);

      for(int k=0; k<6-to_string(j+1).size(); k++) s[P[i][j].second]+='0';

      s[P[i][j].second]+=to_string(j+1);

    }

  }

  for(int i=1; i<=M; i++) cout << s[i] << endl;

  

  return 0;

}

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

#include <iomanip>

#include <string>

#include <vector>

#include <algorithm>



using namespace std;



int main(){

  int N, M;

  cin >> N >> M;

  vector<pair<int, int> > P[100010];

  int s1[100010];

  int s2[100010];

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

    int p, y;

    cin >> p >> y;

    P[p].emplace_back(make_pair(y,i));

  }

  for(int i=1; i<=N; i++) sort(P[i].begin(), P[i].end());

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

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

      s1[P[i][j].second]=i;

      s2[P[i][j].second]=j+1;

    }

  }

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

    cout.fill('0');

    cout << setw(6) << s1[i];

    cout << setw(6) << s2[i] << endl;

  }

  

  return 0;

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

using namespace std;

typedef pair<int,int> A;

#define int long long

int N,M;

pair<int , int> K[100001];

signed main() {

    cin >> N >> M;

    vector<A>vec[100001];

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

        int P,Y;

        cin >> P >> Y;

        vec[P].push_back(A(Y,i));

    }

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

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

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

        	K[vec[i][j].second].first = i;

       	    K[vec[i][j].second].second = j+1;

        }

    }

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

        printf("%06d" "%06d\n",K[i].first,K[i].second);

    }

}

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

using namespace std;

#define int long long

typedef pair<int,int> P;

int INF = 1e16+7;

int mod = 1e9+7;

int dx[4] = {1, 0, -1, 0};

int dy[4] = {0, 1, 0, -1};

signed main(){

    int N,M;

    cin >> N >> M;

    vector<vector<P>>ID(N);

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

        int P,Y;

        cin >> P >> Y;

        P--;

        ID[P].push_back({Y,i});

    }

    vector<P>ans(M);

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

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

        int cnt = 1;

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

            ans[ID[i][j].second] = {i+1,cnt};

            cnt++;

        }

    }

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

        int X = ans[i].first;

        int Y = ans[i].second;

        printf("%06lld%06lld\n",X,Y);

    }

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

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

#define P pair<int,int>

#define int long long

#define LONG LLONG_MAX/3;

#define INT INT_MAX/3;

#define mod 1000000007

typedef long long ll;

using namespace std;



pair<P,int> p[100000];

string s[100000];



int keta(int a){

	int b=0;

	while(a){

		a/=10;

		b++;

	}

	return b;

}

int mypow(int a,int b){

	if(b==0)return 1;

	if(b%2)return mypow(a,b-1)*a%mod;

	return mypow(a,b/2)*mypow(a,b/2)%mod;

}

int kaijo(int n){

	int ans=1;

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

		ans*=i;

		ans%=mod;

	}

	return ans;

}

int gcd(int a,int b){

	if(b==0) return a;

	return gcd(b,a%b);

}

int lcm(int a,int b){

	return a/gcd(a,b)*b;

}



signed main(){

	int n,m,x=1;

	cin>>n>>m;

	f(i,m){

		cin>>p[i].first.first>>p[i].first.second;

		p[i].second=i;

	}

	sort(p,p+m);

	f(i,m){

		if(i){

			if(p[i].first.first==p[i-1].first.first) x++;

			else x=1;

		}

		f(j,6-keta(p[i].first.first)) s[p[i].second]+="0";

		s[p[i].second]+=to_string(p[i].first.first);

		f(j,6-keta(x)) s[p[i].second]+="0";

		s[p[i].second]+=to_string(x);

	}

	f(i,m) cout<<s[i]<<endl;

	return 0;

}


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

#define int long long

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

#define F first

#define S second

#define mod 1000000007

#define P pair<int,int>

using namespace std;

pair<P,int> p[100000];

P x[100000];

signed main(){

	int a,b;

	cin>>a>>b;

	f(i,b){

		cin>>p[i].F.F>>p[i].F.S;

		p[i].S=i;

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

	}

	sort(p,p+b);

	int z=1;

	f(i,b){

		if(i&&p[i].F.F!=p[i-1].F.F){

			z=1;

		}

		x[p[i].S].S=z;

		z++;

	}

	f(i,b){

		int c=6,d=x[i].F;

		while(d){

			d/=10;

			c--;

		}

		f(i,c) cout<<0;

		cout<<x[i].F;

		c=6;

		d=x[i].S;

		while(d){

			d/=10;

			c--;

		}

		f(i,c) cout<<0;

		cout<<x[i].S<<endl;

	}

	return 0;

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

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

#define P pair<int,int>

#define int long long

#define LONG LLONG_MAX/3;

#define INT INT_MAX/3;

#define mod 1000000007

typedef long long ll;

using namespace std;



pair<P,int> p[100000];

string s[100000];



int keta(int a){

	int b=0;

	while(a){

		a/=10;

		b++;

	}

	return b;

}

int mypow(int a,int b){

	if(b==0)return 1;

	if(b%2)return mypow(a,b-1)*a%mod;

	return mypow(a,b/2)*mypow(a,b/2)%mod;

}

int kaijo(int n){

	int ans=1;

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

		ans*=i;

		ans%=mod;

	}

	return ans;

}

int gcd(int a,int b){

	if(b==0) return a;

	return gcd(b,a%b);

}

int lcm(int a,int b){

	return a/gcd(a,b)*b;

}



signed main(){

	int n,m,x=1;

	cin>>n>>m;

	f(i,m){

		cin>>p[i].first.first>>p[i].first.second;

		p[i].second=i;

	}

	sort(p,p+m);

	f(i,m){

		if(i){

			if(p[i].first.first==p[i-1].first.first) x++;

			else x=1;

		}

		f(j,6-keta(p[i].first.first)) s[p[i].second]+="0";

		s[p[i].second]+=to_string(p[i].first.first);

		f(j,6-keta(x)) s[p[i].second]+="0";

		s[p[i].second]+=to_string(x);

	}

	f(i,m) cout<<s[i]<<endl;

	return 0;

}


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

#define int long long

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

#define F first

#define S second

#define mod 1000000007

#define P pair<int,int>

using namespace std;

pair<P,int> p[100000];

P x[100000];

signed main(){

	int a,b;

	cin>>a>>b;

	f(i,b){

		cin>>p[i].F.F>>p[i].F.S;

		p[i].S=i;

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

	}

	sort(p,p+b);

	int z=1;

	f(i,b){

		if(i&&p[i].F.F!=p[i-1].F.F){

			z=1;

		}

		x[p[i].S].S=z;

		z++;

	}

	f(i,b){

		int c=6,d=x[i].F;

		while(d){

			d/=10;

			c--;

		}

		f(i,c) cout<<0;

		cout<<x[i].F;

		c=6;

		d=x[i].S;

		while(d){

			d/=10;

			c--;

		}

		f(i,c) cout<<0;

		cout<<x[i].S<<endl;

	}

	return 0;

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

#include<vector>

#include<algorithm>

using namespace std;

typedef long long ll;

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

const int limit = 100000;

int N, M;

int P[limit], Y[limit];

vector<int> yd[limit + 1];

int main() {

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

    rep(i, M) {

        scanf("%d%d", &P[i], &Y[i]);

        yd[P[i]].push_back(Y[i]);

    }

    rep(i, N) {

        sort(yd[i + 1].begin(), yd[i + 1].end()); //県ごとにyear並び替え

    }

    rep(i, M) {

        printf("%012lld\n", ll(P[i]) * limit * 10 + int(lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin()) + 1);

    }

    return 0;

}


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

#include<vector>

#include<algorithm>

#include<queue>

#include<map>

#include<stack>

#include<cmath>

#include<iomanip>

#include<set>

#include<numeric>

#include<sstream>

#include<random>

#include<cassert>

using namespace std;

typedef long long ll;

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

#define rrep(i, st, n) for (int i = st; i < n; ++i)

using pii = pair<int, int>;

const int inf = 1e9 + 7;

int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};

int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

#define ceil(a, b) a / b + !!(a % b)



int keta(int a) {

    int c = 0;

    while (a) {

        a /= 10;

        c++;

    }

    return c;

}

bool comp(pair<pii, int> lhs, pair<pii, int> rhs) {

    if (lhs.first.first != rhs.first.first)

        return lhs.first.first < rhs.first.first;

    if (lhs.first.second != rhs.first.second)

        return lhs.first.second < rhs.first.second;

    return lhs.first.first < rhs.first.first;

}

int main() {

    int n, m; cin >> n >> m;

    //n = 10; m = 100;

    vector<pair<pii, int> > v;

    rep(i, m) {

        int p, y; cin >> p >> y;

        //p = (i + 10) / 10; y = i % 10 + 1;

        v.push_back({{p, y}, i});

    }

    sort(v.begin(), v.end(), comp);

    /*

    rep(i, v.size()) {

        cout << v[i].first.first << " " << v[i].first.second << " " << v[i].second << endl;

    }

     */

    vector<string> vv(m);

    int c = 1;

    rep(i, v.size()) {

        rep(j, 6 - keta(v[i].first.first)) {

            vv[v[i].second] += '0';

        }

        vv[v[i].second] += to_string(v[i].first.first);

        if (i == 0) {

            vv[v[i].second] += "000001";

        } else if (v[i].first.first == v[i - 1].first.first) {

            c++;

            rep(j, 6 - keta(c)) {

                vv[v[i].second] += '0';

            }

            vv[v[i].second] += to_string(c);

        } else {

            c = 1;

            vv[v[i].second] += "000001";

        }

    }

    rep(i, vv.size()) {

        cout << vv[i] << endl;

    }

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

using namespace std;



typedef long long ll;

typedef pair<int, int> ii;

const int mod = 1e9+7;

const ll INF = 1e18;

const int inf = 1e9;



void solve()

{

  int n,m;cin>>n>>m;

  vector<int> p(m, 0);

  vector<int> y(m, 0);

  vector<vector<int>> yd(100001);

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

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

    yd[p[i]].push_back(y[i]);

  }

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

    sort(yd[i+1].begin(),yd[i+1].end());

  }

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

    int pos = int(lower_bound(yd[p[i]].begin(),yd[p[i]].end(),y[i])-yd[p[i]].begin())+1;

    printf("%06d%06d\n", p[i], pos);

  }

}



int main()

{

  solve();

  return 0;

}


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

using namespace std;

#define rep(i, a) for(int i=0; i<(a); i++)

typedef long long ll;



#ifdef _DEBUG

inline void dump() { cerr << endl; }

template<typename Head> void dump(Head&& head) { cerr << head; dump(); }

template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }

#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)

#else

#define dump(...)

#define debug(...)

#endif



template<typename T>

struct edge {

  int src, to;

  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {

    to = x;

    return *this;

  }

  operator int() const { return to; }

};

template<typename T>

using Edges = vector<edge<T>>;

template<typename T>

using WeightedGraph = vector<Edges<T>>;

using UnWeightedGraph = vector<vector<int>>;

template<typename T>

using Matrix = vector<vector<T>>;



/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;



struct S {

  int p, y, i;

};



bool comp(pair<int,int> a, pair<int,int> b)

{

  if (a.second != b.second) {

    return a.second < b.second;

  }

  return a.first < b.first;

}



bool c1(S a, S b)

{

  if (a.p != b.p) {

    return a.p < b.p;

  }

  return a.y < b.y;

}



bool c2(S a, S b)

{

  return a.i < b.i;

}



int main()

{

  ll n, m; cin>>n>>m;

  vector<S> a(m);

  rep(i, m) {

    int p, y; cin>>p>>y;

    a[i] = S{p, y, i};

  }

  sort(a.begin(),a.end(), c1);

  a[0].y = 1;

  rep(i, m) {

    if (a[i].p == a[i-1].p) a[i].y = a[i-1].y+1;

    else a[i].y = 1;

  }

  sort(a.begin(),a.end(), c2);

  rep(i, m) {

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

  }



  return 0;

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

#include <algorithm>

#include <cstring>

#include <cstdio>

#include <vector>

#include <queue>

#include <stack>

#include <cstdlib>

#include <iomanip>

#include <cmath>

#include <cassert>

#include <ctime>

#include <cstdlib>

#include <map>

#include <set>

using namespace std;

#pragma comment(linker, "/stck:1024000000,1024000000")

#define lowbit(x) (x&(-x))

#define max(x,y) (x>=y?x:y)

#define min(x,y) (x<=y?x:y)

//#define MAX 100000000000000000

#define MOD 1000000007

#define pi acos(-1.0)

#define ei exp(1)

#define PI 3.1415926535897932384626433832

#define ios() ios::sync_with_stdio(true)

#define INF (1<<31)-1;

#define mem(a) (memset(a,0,sizeof(a)))

struct P{

    int x,y;

}H[200000];

vector<int>G[200000];

int POS(int k,int value){

    int mid;

    int left = 0;

    int len = G[k].size();

    int right = len - 1;

    //cout<<" "<<k<<"A"<<value<<endl;

    while(left <= right){

 

        // 确保中点靠近区间的起点

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

        //cout<<mid<<endl;

        //cout<<"mid= "<<mid<<" "<<left<<" "<<right<<endl;

        // 如果找到则返回

        if(G[k][mid] == value) return mid;

        // 将中点赋给终点

        else if(G[k][mid] > value) right = mid;

        // 将中点加一赋给起点

        else left = mid + 1;

    }

    return -1;

}

set<int>::iterator it;

int main()

{

    set<int>s;

    int N,M;

    int x,y;

    cin>>N>>M;

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

        cin>>x>>y;

        H[i].x = x;

        H[i].y = y;

        G[x].push_back(y);

        s.insert(x);

    }

    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;

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

    }

    return 0;

}

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

#include<iostream>

#include<fstream>

#include<algorithm>

#include<functional>

#include<cstring>

#include<string>

#include<cstdlib>

#include<iomanip>

#include<numeric>

#include<cctype>

#include<cmath>

#include<ctime>

#include<queue>

#include<stack>

#include<list>

#include<set>

#include<map>

using namespace std;

#define N 100000+5

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

#define sd(n) scanf("%d",&n)

#define sll(n) scanf("%I64d",&n)

#define pd(n) scanf("%d\n",n)

#define pll(n) scanf("%I64d\n",n)

#define MAX 26

typedef long long ll;

const ll mod=1e9+7;

int n,m;

int a[N];

int b[N];

vector<int>p[N];

int main()

{

	 //string s;

	 //cin>>s;

	 //ll ans=0;

	 //ll sum=0;

	scanf("%d",&n);

	scanf("%d",&m);

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

	{

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

		p[a[i]].push_back(b[i]);

	}

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

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

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

	{



		int pos=lower_bound(p[a[i]].begin(),p[a[i]].end(),b[i])-p[a[i]].begin()+1;

		printf("%06d%06d\n",a[i],pos);

	}

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

	//	printf("%I64d",a[i]);

		

	//printf("%I64d\n",ans);

    return 0;

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

#include <iomanip>

#include <iostream>

#include <set>

#include <string>

#include <vector>

#define SORT(a) sort((a).begin(), (a).end())

#define RSORT(a) sort((a).rbegin(), (a).rend())

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

#define ALL(a) a.begin(), a.end()

using namespace std;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);



    int n, m;

    cin >> n >> m;



    int p[100000], y[100000];

    vector<int> yd[100001];

    REP(i, m) {

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

        yd[p[i]].push_back(y[i]);

    }



    REP(i, n) { SORT(yd[i + 1]); }

    REP(i, m) {

        cout << setfill('0') << setw(6) << p[i];

        cout << setfill('0') << setw(6)

             << lower_bound(ALL(yd[p[i]]), y[i]) - yd[p[i]].begin() + 1 << endl;

    }



    return 0;

}

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

#include <iomanip>

#include <iostream>

#include <queue>

#include <set>

#include <string>

#include <vector>

#define SORT(a) sort(a.begin(), a.end())

#define RSORT(a) sort(a.rbegin(), a.rend())

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

#define RREP(i, n) for (int i = n; 0 <= i; i--)

#define FOR(i, start, end) for (int i = start; i < end; i++)

#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)

#define ALL(a) a.begin(), a.end()

#define MOD(a) a %= 1000000007

typedef long long ll;

const int INF32 = 2147483647;

const ll INF64  = 9223372036854775807;

using namespace std;



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);



    int N, M;

    cin >> N >> M;

    vector<pair<int, pair<int, int>>> A(M);

    REP(i, M) {

        int a, b;

        cin >> a >> b;

        A[i].first         = a;

        A[i].second.first  = b;

        A[i].second.second = i;

    }

    vector<pair<int, pair<int, int>>> B = A;

    SORT(B);

    vector<int> index(M);

    vector<int> id(N + 1, 1);

    REP(i, M) {

        index[B[i].second.second] = id[B[i].first];

        id[B[i].first]++;

    }



    REP(i, M) {

        cout << setfill('0') << setw(6) << A[i].first;

        cout << setfill('0') << setw(6) << index[i] << '\n';

    }



    return 0;

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

using namespace std;



typedef long long int ll;

typedef pair<ll, ll> pll;



#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))

#define REP(i, n) FOR(i, n, 0)

#define OF64 std::setprecision(10)



const ll MOD = 1000000007;

const ll INF = (ll)1e15;



struct Data

{

    int y;

    int p;

    int i;

};

Data D[100005];

string A[100005];



string create(int p, int n)

{

    string a = "", b = "";

    REP(i, 6)

    {

        a = (char)('0' + p % 10)+a;

        b = (char)('0' + n % 10)+b;

        p /= 10;

        n /= 10;

    }

    return a + b;

}



int main()

{

    int N, M;

    cin >> N >> M;

    REP(i, M)

    {

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

        D[i].i = i;

    }

    sort(D, D + M, [](Data a, Data b) { return a.p == b.p ? a.y < b.y : a.p < b.p; });

    int pi = 0;

    REP(i, M)

    {

        if (D[pi].p != D[i].p)

        {

            pi = i;

        }

        A[D[i].i] = create(D[i].p, i - pi + 1);

    }

    REP(i, M)

    {

        cout << A[i]<<endl;

    }

    return 0;

}

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

using namespace std;



typedef long long int ll;

typedef pair<ll, ll> pll;



#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))

#define REP(i, n) FOR(i, n, 0)

#define OF64 std::setprecision(10)



const ll MOD = 1000000007;

const ll INF = (ll)1e15;



struct Data

{

    ll P;

    ll Y;

    ll i;

};

Data D[100005];

pll A[100005];



int main()

{

    ll N, M;

    cin >> N >> M;

    REP(i, M)

    {

        cin >> D[i].P >> D[i].Y;

        D[i].i = i;

    }

    sort(D, D + M, [](Data a, Data b) { return a.P == b.P ? a.Y < b.Y : a.P < b.P; });

    int num = 1;

    REP(i, M)

    {

        if (i == 0 || D[i].P != D[i - 1].P)

            num = 1;

        A[D[i].i].first = D[i].P;

        A[D[i].i].second = num++;

    }



    REP(i, M)

    {

        cout << std::setfill('0') << std::right << std::setw(6) << A[i].first;

        cout << std::setfill('0') << std::right << std::setw(6) << A[i].second;

        cout << endl;

    }

    return 0;

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

using namespace std;



int main(){

    int N,M;

    cin>>N>>M;

    

    map<int,int> Year;

    map<int,int> origin;

    vector<int> P(M);

    vector<int> Y(M);

    int i;

    

    

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

        cin>>P[i]>>Y[i];

        Year[Y[i]]=P[i];

        origin[Y[i]]=i;

    }

    

    

    sort(Y.begin(),Y.end());

    

    for(i=0;i<M;i++)P[i]=Year[Y[i]];

    

    int up[M];

    int down[M];

    int sum[100001]={0};

    

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

        up[origin[Y[i]]]=P[i];

        sum[P[i]]++;

        down[origin[Y[i]]]=sum[P[i]];

        

    }

    

    for(i=0;i<M;i++)printf("%06d%06d\n",up[i],down[i]);

    

}

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

using namespace std;

typedef pair<int,int> P;

int main(){

    int N, M;

    cin >> N >> M;

    vector<int> v[N];

    vector<P> sub(M);

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

        int p, y;

        cin >> p >> y;

        p--;

        v[p].push_back(y);

        sub[i] = P(p, y);

    }

    

    map<P,int> ma;

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

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

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

            ma[P(i, v[i][j])] = j + 1;

        }

    }

    

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

        int p = sub[i].first + 1;

        int num = ma[sub[i]];

        printf("%06d%06d\n", p, num);

    }

}