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: Accepted)

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author edamat
 */

#include <bits/stdc++.h>

using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a), i##_len = (b); i < i##_len; ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _repr(i, n) repri(i, n, 0)
/* loop in [n,m] step -1 */
#define repri(i, a, b) for(int i = int(a), i##_len = (b); i >= i##_len; --i)
/* loop in [n,0] step -1 or [n,m] step -1 */
#define repr(...) _overload3(__VA_ARGS__, repri, _repr, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define pb push_back
#define append emplace_back
#define eb emplace_back
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define SZ(x) ((int)(x).size())
#define endl '\n'
typedef long long lint;
//#define int lint
const int INF = numeric_limits<int>::max();
//int MOD = (int) 1e9 + 7;
//const double EPS = 1e-9;
const lint LINF = (lint) (1LL << 62) - 1;
typedef vector<int> vint;
typedef pair<int, int> pint;

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
//        cout << fixed << setprecision(20);
//        cerr << fixed << setprecision(20);
    }
} iosetup;


using std::to_string;

auto to_string(std::string s) -> std::string {
    return s;
}

auto to_string(char c) -> std::string {
    return std::string{c};
}

auto to_string(const char *s) -> std::string {
    return to_string((std::string) s);
}

auto to_string(bool b) -> std::string {
    return (b?"true":"false");
}

template<typename T, typename U>
auto to_string(std::pair<T, U> p) -> std::string {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template<size_t N>
auto to_string(std::bitset<N> bs) -> std::string {
    std::string res{};
    for(size_t i = 0; i < N; i++)
        res.insert(res.begin(), bs.test(i)?'1':'0');
    return res;
}

template<typename T>
auto to_string(T v) -> std::string {
    bool flg = false;
    std::string res = "[";
    for(auto const &x : v){
        if(flg) res += ", ";
        else flg = true;
        res += to_string(x);
    }
    res += "]";
    return res;
}

/* keep a max,min */
template<class T>
bool chmax(T &a, const T &b) {
    if(a < b){
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
bool chmin(T &a, const T &b) {
    if(a > b){
        a = b;
        return 1;
    }
    return 0;
}
/* gcd */
template<typename T>
T gcd(const T &a,const T &b){
    if (b == 0) return a;
    else return gcd(b, a % b);
}

template<typename T>
T gcd(vector<T> &v) {
    T ret=v[0];
    for(auto x:v){
        ret = gcd(ret,x);
    }
    return ret;
}

template<typename T, typename... A>
auto gcd(const T &first, const A &... rest) {
    return gcd(first,gcd(rest...));
}

/* initialize vector. usage: auto v = male_v<int>(N,0); */
template<typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

/* fill vector. usage: fill_v(v,0); */
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for(auto &e : t) fill_v(e, v);
}


/* input,output operator for pair and vector */
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << " " << p.second;
    return os;
}

template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for(int i = 0; i < (int) v.size(); i++){
        os << v[i] << (i + 1 != v.size()?" ":"");
    }
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
    for(int i = 0; i < (int) v.size(); i++){
        os << v[i] << (i + 1 != v.size()?"\n":"");
    }
    return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for(T &in : v) is >> in;
    return is;
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
    os << "{";
    for(auto x = mp.begin(); x != mp.end(); ++x){
        os << x->first << ":" << x->second
           << (x != prev(mp.end())?", ":"");
    }
    os << "}";
    return os;
}

/* sum */
template<typename T>
lint sum(vector<T> &v) {
    lint ret = 0;
    for(auto x : v){
        ret += x;
    }
    return ret;
}

double sum(vector<double> &v) {
    double ret = 0;
    for(auto x : v){
        ret += x;
    }
    return ret;
}

template<typename T>
auto sum(const T &a) {
    return a;
}

template<typename T, typename... A>
auto sum(const T &first, const A &... rest) {
    return sum(first) + sum(rest...);
}



/* Modint */
template <typename T, T MOD = 1000000007>
struct ModInt {
    static constexpr T mod = MOD;
    T v;
    ModInt() : v(0) {}
    ModInt(signed v) : v(v) {}
    ModInt(long long t) {
        v = t % MOD;
        if(v < 0) v += MOD;
    }

    ModInt pow(long long k) {
        ModInt res(1), tmp(v);
        while(k) {
            if(k & 1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    static ModInt add_identity() { return ModInt(0); }
    static ModInt mul_identity() { return ModInt(1); }

    ModInt inv() { return pow(MOD - 2); }

    ModInt &operator+=(ModInt a) {
        v += a.v;
        if(v >= MOD) v -= MOD;
        return *this;
    }
    ModInt &operator-=(ModInt a) {
        v += MOD - a.v;
        if(v >= MOD) v -= MOD;
        return *this;
    }
    ModInt &operator*=(ModInt a) {
        v = 1LL * v * a.v % MOD;
        return *this;
    }
    ModInt &operator/=(ModInt a) { return (*this) *= a.inv(); }

    ModInt operator+(ModInt a) const { return ModInt(v) += a; };
    ModInt operator-(ModInt a) const { return ModInt(v) -= a; };
    ModInt operator*(ModInt a) const { return ModInt(v) *= a; };
    ModInt operator/(ModInt a) const { return ModInt(v) /= a; };

    ModInt operator-() const { return v ? ModInt(MOD - v) : ModInt(v); }

    bool operator==(const ModInt a) const { return v == a.v; }
    bool operator!=(const ModInt a) const { return v != a.v; }
    bool operator<(const ModInt a) const { return v < a.v; }

    // find x s.t. a^x = b
    static T log(T a, T b) {
        const T sq = 40000;
        unordered_map<T, T> dp;
        dp.reserve(sq);
        ModInt res(1);
        for(int r = 0; r < sq; r++) {
            if(!dp.count(res.v)) dp[res.v] = r;
            res *= a;
        }
        ModInt p = ModInt(a).inv().pow(sq);
        res = b;
        for(int q = 0; q <= MOD / sq + 1; q++) {
            if(dp.count(res.v)) {
                T idx = q * sq + dp[res.v];
                if(idx > 0) return idx;
            }
            res *= p;
        }
        assert(0);
        return T(-1);
    }
    
    static ModInt perm(long long n, int k) {
        ModInt num(1);
        for(int i = 0; i < k; i++) {
            num *= ModInt(n - i);
        }
        return num;
    }

    static ModInt comb(long long n, int k) {
        ModInt num(1), dom(1);
        for(int i = 0; i < k; i++) {
            num *= ModInt(n - i);
            dom *= ModInt(i + 1);
        }
        return num / dom;
    }
};
template <typename T, T MOD>
constexpr T ModInt<T, MOD>::mod;
template <typename T, T MOD>
ostream &operator<<(ostream &os, ModInt<T, MOD> m) {
    os << m.v;
    return os;
}


struct RandomNumberGenerator {
    mt19937 mt;
    
    RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}
    
    int operator()(int a, int b) { // [a, b)
        uniform_int_distribution<int> dist(a, b - 1);
        return dist(mt);
    }
    
    int operator()(int b) { // [0, b)
        return (*this)(0, b);
    }
};


struct CID {
    
    static constexpr int kStressIterations = 1;
    
    static void generateTest(int cnt, std::ostream &test) {
        RandomNumberGenerator rng;
        int N = 100000;
        int M = 100000;
        test << N << " " << M << endl;
        rep(i, N){
            test << rng(1,3) << " " << rng(1, 1000000000) << endl;
        }
    }
    
    struct City {
        int P, Y;
        int index;
        int J;
        
        City() {}
        
        City(int i, int x, int y) {
            index = i;
            P = x;
            Y = y;
        }
        
        bool operator<(const City &another) const {
            if(P != another.P){
                return P < another.P;
            } else {
                return Y < another.Y;
            }
        };
        
        int rp(){return P;}
    };
    
    void solve(std::istream &cin, std::ostream &cout) {
        int N, M;
        cin >> N >> M;
        vector<City> Cities;
        Cities.reserve(M);
        rep(i, M){
            int P, Y;
            cin >> P >> Y;
            Cities.emplace_back(City(i, P, Y));
        }
        sort(all(Cities));
        int index = 0;
        int cnt = 1;
        int last = Cities[0].rp();
        while(index < M){
            if(Cities[index].rp() !=last){
                cnt = 1;
                last = Cities[index].rp();
            }
            Cities[index].J = cnt;
            cnt++;
            index++;
        }
        sort(all(Cities), [](const City &a, const City &b) {
            return a.index < b.index;
        });
        rep(i, M) cout << setw(6) << setfill('0') << Cities[i].P << setw(6) << Cities[i].J << endl;
    }
};


signed main() {
	CID solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}