Problem:
Score: 300 points

Problem Statement

In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.

City i is established in year Y_i and belongs to Prefecture P_i.

You can assume that there are no multiple cities that are established in the same year.

It is decided to allocate a 12-digit ID number to each city.

If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.

Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.

Find the ID numbers for all the cities.

Note that there can be a prefecture with no cities.

Constraints

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq P_i \leq N

1 \leq Y_i \leq 10^9

Y_i are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
P_1 Y_1
:
P_M Y_M

Output

Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

Sample Input 1

2 3
1 32
2 63
1 12

Sample Output 1

000001000002
000002000001
000001000001

As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.

As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.

As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

Sample Input 2

2 3
2 55
2 77
2 99

Sample Output 2

000002000001
000002000002
000002000003

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
ll keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
ll keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
ll ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

struct data{
  ll od;
  ll pref;
  ll year;
  string id;
};

bool func(data x,data y){
  if(x.pref<y.pref){ return true;}
  else{ return x.year<y.year; }
}
bool func2(data x,data y){
  return x.od<y.od;
}

ll solve(){
  ll N,M; cin>>N>>M;
  data d[M];
  REP(i,M){
    ll p,y; cin>>p>>y;
    d[i] = {i,p,y,""};
  }
  sort(d,d+M,func);
  d[0].id = string((int)(6-keta(d[0].pref)  ),'0') + to_string(d[0].pref) + "000001";
  ll buf = 1;
  ll pre_p = d[0].pref;
  REP(i,N){
    if(d[i+1].pref==d[i].pref){ ++buf;}
    else{buf = 1;}
    d[i+1].id = string(6-keta(d[i+1].pref),'0') + to_string(d[i+1].pref) 
                      + string(6-keta(buf),'0') + to_string(buf);
  }
  sort(d,d+M,func2);
  REP(i,M){
    cout << d[i].id <<"\n";
  }
  return 0;
}

int main(){
  solve();
}