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)

#include <cstdio>
#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <cstddef>
#include <cinttypes>

#include <type_traits>
#include <limits>
#include <vector>
#include <algorithm>

/* FastIO by rsk0315 (last update: 2018/02/21 00:36) */

namespace FastIn {
  static constexpr size_t BUF_SIZE=1<<17, INT_LEN=24, FLT_LEN=400;
  static char buf[BUF_SIZE|1]={}, *pos=buf, *endbuf=nullptr;
  FILE *fin;

  inline bool rebuffer() {
    // returns true <=> there is at least one unread character
    size_t rest=endbuf-pos;
    if (buf+rest > pos) {
      // buf[:pos] and buf[-pos:] are overlapping, which std::memcpy()
      // causes undefined behavior.
      return true;
    }

    std::memcpy(buf, pos, rest); 
    pos = buf;
    size_t len=std::fread(pos+rest, 1, BUF_SIZE-rest, fin);
    *(endbuf = buf + (rest+len)) = 0;

    return *pos;
  }

  inline bool scan(char &in) {
    if ((in = *pos)) {
      ++pos;
      return true;
    }

    return rebuffer() && (in = *pos++);
  }

  inline bool scan(char *in) {
    if ((*in = *pos) == 0) {
      if (rebuffer() && (*in = *pos) == 0) {
        return false;
      }
    }
    ++in;
    while (true) {
      if ((*in = *pos++) == 0) {
        if (rebuffer() && (*in = *pos++) == 0) {
          return true;
        }
      }
      ++in;
    }
  }

  inline bool scan(double &in) {
    if (pos + FLT_LEN >= endbuf && !rebuffer()) {
      in = 0.0;
      return false;
    }

    char *tmp;
    in = std::strtod(pos, &tmp);
    pos = tmp;
    return true;
  }

  template <class Int>
  inline bool scan(Int &in) {
    in = 0;

    // assume that no redundant whitespace appears
    if (pos + INT_LEN >= endbuf && !rebuffer()) {
      return false;
    }

    if (std::is_signed<Int>::value) {
      if (*pos == '-') {
        in = ~*++pos+'1';
        while (*++pos >= '0') {
          in = in*10 + ~*pos+'1';
        }
        ++pos;
        return true;
      }
    }

    // assume that numbers are separated by the character whose value is
    // less than '0' (e.g. whitespaces, newlines)
    do {
      in = in*10 + *pos-'0';
    } while (*++pos >= '0');
    ++pos;
    return true;
  }

  inline bool eat() {
    if (*pos > ' ') {
      return true;
    }

    do {
      if (*pos == 0 && !rebuffer()) {
        return false;
      }
    } while (*++pos <= ' ');

    return true;
  }

  inline bool eat(char ch) {
    if (*pos == ch) {
      return true;
    }

    do {
      if (*pos == 0 && !rebuffer()) {
        return false;
      }
    } while (*++pos != ch);

    return true;
  }

  class Scanner {
    bool rebuffer() {
      return FastIn::rebuffer();
    }

  public:
    Scanner(FILE *fin=stdin) {
      FastIn::fin = fin;
      endbuf = pos + std::fread(buf, 1, BUF_SIZE, fin);
    }

    template <class T>
    inline bool scan(T &in) {
      return FastIn::scan(in);
    }

    template <class First, class... Rest>
    inline bool scan(First &in, Rest &...ins) {
      return scan(in) && scan(ins...);
    }
  };
}


namespace FastOut {
  static constexpr size_t BUF_SIZE=1<<17, INT_LEN=7, FLT_LEN=400;
  static constexpr char FLT_FMT[]="%.16f";
  static char buf[BUF_SIZE|1]={}, *pos=buf, *endbuf=pos+BUF_SIZE;
  FILE *fout;

  inline void flush() {
    std::fwrite(buf, 1, pos-buf, fout);
    pos = buf;
  }

  inline void print(const char out) {
    if (pos == endbuf) {
      flush();
    }
    *pos++ = out;
  }

  inline void print(const char *out) {
    size_t len=std::strlen(out);
    if (pos + len >= endbuf) {
      flush();
      if (len >= BUF_SIZE) {
        std::fwrite(out, 1, len, fout);
        return;
      }
    }
    std::memcpy(pos, out, len);
    pos += len;
  }

  inline void print(char *out) {
    size_t len=std::strlen(out);
    if (pos + len >= endbuf) {
      flush();
      if (len >= BUF_SIZE) {
        std::fwrite(out, 1, len, fout);
        return;
      }
    }
    std::memcpy(pos, out, len);
    pos += len;
  }


  template <class Char, size_t Len>
  inline void print(const Char (&out)[Len]) {
    print(&out[0]);
  }

  inline void print(const double out) {
    char minibuf[FLT_LEN];
    size_t len=std::snprintf(minibuf, FLT_LEN, FLT_FMT, out);
    if (pos + len >= endbuf) {
      flush();
    }
    std::memcpy(pos, minibuf, len);
    pos += len;
  }

  inline void print(const bool out) {
    print(out? "true":"false");
  }

  template <class Int>
  inline void print(Int out) {
    static_assert(std::is_integral<Int>::value, "For integers only");

    if (out == 0) {
      if (pos == endbuf) {
        flush();
      }
      *pos++ = '0';
      return;
    }

    // "%06u"
    char minibuf[INT_LEN]="000000", *minipos=minibuf+INT_LEN-1;
    if (std::is_signed<Int>::value && out < 0) {
      if (pos == endbuf) {
        flush();
      }
      *pos++ = '-';
      if (out == std::numeric_limits<Int>::min() && Int(-1) == ~Int(0)) {
        // In two's complement representation, we could not represent the
        // absolute value of minimum (maximum-magnitude negative) value.
        // Without this branch, we would overflow (undefined behavior) by
        // the value.  If we know the input is never the value, we can
        // remove this branch and save (nanoseconds-order) time.
        switch (sizeof out) {
        case 1:
          return (void)(print("128"));
        case 2:
          return (void)(print("32768"));
        case 3:
          return (void)(print("8388608"));
        case 4:
          return (void)(print("2147483648"));
        case 8:
          return (void)(print("9223372036854775808"));
        case 16:
          return (void)(print("170141183460469231731687303715884105728"));
        default:
          // Regardless of the number of its bytes, lowest (decimal) digit
          // is always eight, but other digits depend on it.
          *--minipos = '8';
          out /= -10;
        }
      } else {
        out = -out;
      }
    }

    // We know the division is too slow; we wish we could avoid using them
    // TWICE PER LOOP!  ...Now, we notice that compilers are so smart that
    // can replace it by shift operations...  The division-compatible
    // instructions for unsigned are shorter than ones for signed.
    typename std::make_unsigned<Int>::type out_=out;
    do {
      *--minipos = '0' + out_%10;
      out_ /= 10;
    } while (out_ > 0);

    size_t len=INT_LEN-1;
    if (pos + len >= endbuf) {
      flush();
    }
    std::memcpy(pos, minibuf, len);
    pos += len;
  }

  class Printer {
    inline void flush() {
      FastOut::flush();
    }

  public:
    Printer(FILE *fout=stdout) {
      FastOut::fout = fout;
    }

    ~Printer() {
      flush();
    }

    template <class T>
    inline void print(const T out) {
      FastOut::print(out);
    }

    template <class First, class... Rest>
    inline void print(const First &out, const Rest &...outs) {
      FastOut::print(out);
      Printer::print(outs...);
    }

    template <class T>
    inline void println(const T out) {
      FastOut::print(out);
      FastOut::print('\n');
    }
  };
}

FastIn::Scanner cin;
FastOut::Printer cout;

int main() {
  size_t N, M;
  cin.scan(N, M);

  std::vector<uintmax_t> B(M);
  std::vector<uintmax_t> res0(M), res1(M);
  for (size_t i=0; i<M; ++i) {
    uintmax_t y;
    cin.scan(res0[i], y);
    B[i] = y<<17|i;
  }

  std::sort(B.begin(), B.end());

  std::vector<unsigned> count(N+1);
  for (size_t i=0; i<M; ++i) {
    size_t j=B[i]&0x1FFFFuLL;
    res1[j] = ++count[res0[j]];
  }

  for (size_t i=0; i<M; ++i)
    cout.print(res0[i], res1[i], '\n');
}