#!/usr/bin/env python3

(n, m), *q = [[*list(map(int, i.split()))] for i in open(0)]

s = sorted(q)

d = {}

for k, v in s:

    if k not in d:

        d[k] = []

    d[k].append(v)

c = {}

for k, v in list(d.items()):

    i = 0

    if k not in c:

        c[k] = {}

    while i < len(v):

        i += 1

        c[k][v[~-i]] = str(i)

for p, y in q:

    pn = "00000" + str(p)

    cn = "00000" + c[p][y]

    print((pn[-6:] + cn[-6:]))

from collections import defaultdict

(n, m), *q = [[*list(map(int, i.split()))] for i in open(0)]

d = defaultdict(list)

for k, v in q:

    d[k].append(v)

c = defaultdict(dict)

for k, v in list(d.items()):

    for i, j in enumerate(sorted(v)):

        c[k][j] = i + 1

for p, y in q:

    print(("{:0>6}{:0>6}".format(p, c[p][y])))

#!/usr/bin/env python3
(n, m), *q = [[*list(map(int, i.split()))] for i in open(0)]
s = sorted(q)
d = {}
for k, v in s:
    if k not in d:
        d[k] = []
    d[k].append(v)
c = {}
for k, v in list(d.items()):
    i = 0
    if k not in c:
        c[k] = {}
    while i < len(v):
        i += 1
        c[k][v[~-i]] = str(i)
for p, y in q:
    pn = "00000" + str(p)
    cn = "00000" + c[p][y]
    print((pn[-6:] + cn[-6:]))

from collections import defaultdict

(n, m), *q = [[*list(map(int, i.split()))] for i in open(0)]
d = defaultdict(list)
for k, v in q:
    d[k].append(v)
c = defaultdict(dict)
for k, v in list(d.items()):
    for i, j in enumerate(sorted(v)):
        c[k][j] = i + 1
for p, y in q:
    print(("{:0>6}{:0>6}".format(p, c[p][y])))

-#!/usr/bin/env python3 +from collections import defaultdict + -s = sorted(q) -d = {} -for k, v in s: -    if k not in d: -        d[k] = [] +d = defaultdict(list) +for k, v in q: -c = {} +c = defaultdict(dict) -    i = 0 -    if k not in c: -        c[k] = {} -    while i < len(v): -        i += 1 -        c[k][v[~-i]] = str(i) +    for i, j in enumerate(sorted(v)): +        c[k][j] = i + 1 -    pn = "00000" + str(p) -    cn = "00000" + c[p][y] -    print((pn[-6:] + cn[-6:])) +    print(("{:0>6}{:0>6}".format(p, c[p][y])))