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>

#define ULL unsigned long long
#define LL long long

#define P pair<int, int>

#define pb push_back
//#define mp make_pair
#define pp pop_back

#define lson root << 1
#define rson root << 1 | 1

#define INF32 (int)1e9 + 7
#define INF64 (long long)1e18

#define sc(x) scanf("%d", &x)
#define pr(x) printf("%d\n", x)

#define mem(arry, in) memset(arry, in, sizeof(arry))

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

#define BEGIN() int T; sc(T); while(T--)

#define rep(i, aa, bb) for (int i = aa; i < bb; ++i)
#define Rep(i, aa, bb) for (int i = aa; i <= bb; ++i)

#define Size(x) (int)(x).size()
#define Range(x) (x).begin(), (x).end()

#define PI acos(-1)

using namespace std;

/*
namespace fastIO {
    #define BUF_SIZE 100000
    bool IOerror = 0;
    inline char nc() {
        static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
        if(p1 == pend) {
            p1 = buf;
            pend = buf + fread(buf, 1, BUF_SIZE, stdin);
            if(pend == p1) {
                IOerror = 1;
                return -1;
            }
        }
        return *p1++;
    }
    inline bool blank(char ch) {
        return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
    }
    inline void read(int &x) {
        char ch;
        while(blank(ch = nc()));
        if(IOerror) return;
        for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
    }
    #undef BUF_SIZE
};
using namespace fastIO;
*/
/*
void print64mul(LL x, LL y) {
#if __SIZEOF_INT128__ == 16
  __int128 res = __int128(x) * y;
  char ch[64];
  int ptr = 0;
  if (res == 0) {
    puts("0");
    return;
  }
  while (res) {
    ch[ptr] = (res % 10) + '0';
    ptr++;
    res /= 10;
  }
  while (ptr)
    putchar(ch[--ptr]);
  putchar('\n');
#else
  constexpr LL limit = 1000000000;
  LL dig[4] = {0};
  dig[0] = x % limit;
  dig[1] = x / limit;
  dig[0] *= y;
  dig[1] *= y;
  dig[1] += dig[0] / limit;
  dig[0] %= limit;
  dig[2] += dig[1] / limit;
  dig[1] %= limit;
  int pos = 2;
  while (pos > 0) {
    if (dig[pos]) break;
    pos--;
  }
  printf("%d", dig[pos]);
  while (pos > 0) {
    pos--;
    printf("%09d", dig[pos]);
  }
  puts("");
#endif
}
*/

const int N = 100005;

int n, m;
int c[N];
vector<int> a[N];

char A[10];

string change(int x) {
    int cnt = 0;
    string op = "";
    while(x) {
        op += A[x % 10];
        x /= 10;
        cnt++;
    }
    string sp = "";
    rep(i, 0, 6 - cnt) sp += '0';
    return (sp + op);
}

string ans[N];

int main()
{
    char tt = '0';
    rep(i, 0, 10) A[i] = tt++;

    cin >> n >> m;
    Rep(i, 1, m) {
        int x, y;
        cin >> x >> y;
        a[x].pb(y);
        c[i] = y;
    }
    Rep(i, 1, n) sort(Range(a[i]));


    Rep(i, 1, n) {
        string op = change(i);

        Rep(j, 1, Size(a[i])) {
            ans[a[i][j - 1]] = op + change(j);
        }

    }

    Rep(i, 1, m) cout << ans[c[i]] << endl;
    return 0;
}