using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    struct ABC113_C
    {
        public int P;
        public int Y;
    }

    public static void Main()
    {
        C();
        return;
        int[] naa = SpRead(' ').Select(i => int.Parse(i)).ToArray();
        int N = naa[0], M = naa[1];
        int[] box;
        int[] Ys = new int[M];
        int[] Ps = new int[M];
        for (int i = 0; i < M; i++)
        {
            box = SpRead(' ').Select(a => int.Parse(a)).ToArray();
            Ys[i] = box[1];
            Ps[i] = box[0];
        }
        Dictionary<Tuple<int, int>, string> ans = new Dictionary<Tuple<int, int>, string>();
        List<int> list = new List<int>();
        for (int i = 1; i <= N; i++)
        {
            list = new List<int>();
            for (int j = 0; j < M; j++)
            {
                if (Ps[j] == i) list.Add(Ys[j]);
            }
            list.Sort();
            for (int j = 0; j < list.Count(); j++)
            {
                string ansString = i.ToString().PadLeft(6, '0') + (j + 1).ToString().PadLeft(6, '0');
                ans.Add(new Tuple<int, int>(i, list[j]), ansString);
            }
        }

        for (int i = 0; i < M; i++)
        {
            Console.WriteLine(ans[new Tuple<int, int>(Ps[i], Ys[i])]);
        }


    }

    public static void C()
    {
        int[] naa = SpRead(' ').Select(i => int.Parse(i)).ToArray();
        int N = naa[0], M = naa[1];
        int[] box;
        int[] Ys = new int[M];
        int[] Ps = new int[M];

        //N個の都市
        List<int>[] listZ = new List<int>[N + 1];
        for (int i = 0; i < N; i++) listZ[i+1] = new List<int>();
        for (int i = 0; i < M; i++)
        {
            box = SpRead(' ').Select(a => int.Parse(a)).ToArray();
            Ys[i] = box[1];
            Ps[i] = box[0];
            listZ[Ps[i]].Add(Ys[i]);
        }
        
        Dictionary<Tuple<int, int>, string> ans = new Dictionary<Tuple<int, int>, string>();

        for (int i = 1; i <= N; i++)
        {
            listZ[i].Sort();
            for (int j = 0; j < listZ[i].Count(); j++)
            {
                string ansString = i.ToString().PadLeft(6, '0') + (j + 1).ToString().PadLeft(6, '0');
                ans.Add(new Tuple<int, int>(i, listZ[i][j]), ansString);
            }
        }
        for (int i = 0; i < M; i++)
        {
            Console.WriteLine(ans[new Tuple<int, int>(Ps[i], Ys[i])]);
        }

    }

}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }

}


Measured memory_bytes: 42032