#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<int> y(m);
  vector<vector<int>> c(n + 1);
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    c[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= n; i++) sort(c[i].begin(), c[i].end());
  for (int i = 0; i < m; i++) {
    printf("%06d%06d\n", p[i],
           lower_bound(c[p[i]].begin(), c[p[i]].end(), y[i]) - c[p[i]].begin() +
               1);
  }
}
