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 (GCC 5.4.1) (judge verdict: Wrong Answer)

// AtCoder ABC113: C - ID
// 2020.1.29 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示（出力）
	int i, k; char b[30];

	i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
	k = 6 - i;
	while (k--) pc('0');
	while (i--) pc(b[i]);

}

#define MAX 100005
typedef struct { int id; ll n; } T;
T t[MAX]; int M;

void Usort(T *a, int n) {
	int i, k;
#define B 8
#define BMSK 255 // (1<<8)-1
	int t1[1 << B], t2[1 << B];
	
	T *tmp = malloc(n * sizeof(T));	
	for (k = 0; k < 6; ++k) {  // for 64ビット
		memset(t1, 0, sizeof(t1)), memset(t2, 0, sizeof(t2));
		for (i = 0; i < n; ++i)	t1[(a[i].n >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t1[i+1] += t1[i];
		i = n; while (i--) tmp[--t1[(a[i].n >> k*B) & BMSK]] = a[i];
		k++;
		for (i = 0; i < n; ++i) t2[(tmp[i].n >> k*B) & BMSK]++;
		for (i = 0; i < BMSK; ++i) t2[i+1] += t2[i];
		i = n; while (i--) a[--t2[(tmp[i].n >> k*B) & BMSK]] = tmp[i];
	}
	free(tmp);
// for (i = 0; i < n; ++i) printf("[%d] %lld\n", i, a[i]);
}

int ap[MAX], ax[MAX];

int main()
{
	int i, N, P, Y, x;
	
	N = in(), M = in();
	for (i = 1; i <= M; ++i) {
		P = in(), Y = in();
		t[i].id = i, t[i].n = ((ll)P << 32) | Y;
		ap[i] = P;
	}
	Usort(t+1, M);
	for (i = 1; i <= M; ++i) {
		if ((t[i].n >> 32) != (t[i-1].n >> 32)) ax[t[i].id] = x = 1;
		else ax[t[i].id] = ++x;
	}
	for (i = 1; i <= M; ++i) {
		out(ap[i]), out(ax[i]), pc('\n');
	}
	return 0;
}