#include <iostream>
#include <algorithm>
#include <vector>
#include <string> 
#include <map>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  map<int, vector<int>> mp;
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    mp[p[i]].push_back(y[i]);
  }
  for (auto &e : mp) sort(e.second.begin(), e.second.end());
  for (int i = 0; i < m; i++) {
    int k = lower_bound(mp[p[i]].begin(), mp[p[i]].end(), y[i]) - mp[p[i]].begin();
    printf("%06d%06d\n", p[i], k + 1);
  }
  return 0;
}
