Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        tmp = shi_map[p]
        tmp.append(y)
        tmp.sort()
        shi_map[p] = tmp

    else:
        shi_map[p] = [y]


for i in range(M):
    p = p_list[i]
    y = y_list[i]
    j = shi_map[p].index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]

for i in range(M):
    p = p_list[i]
    y = y_list[i]
    s_m = shi_map[p]
    s_m = sorted(s_m)
    j = s_m.index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
shi_map2 = {}
for k, v in shi_map.items():
    v = sorted(v)
    shi_map2[k] = v

for i in range(M):
    p = p_list[i]
    y = y_list[i]
    j = shi_map2[p].index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
shi_map = sorted(shi_map.items(), key=lambda x: x[0])
shi_map = dict(shi_map)
shi_map2 = {}
for k, v in shi_map.items():
    v = sorted(v)
    shi_map2[k] = v

for i in range(M):
    p = p_list[i]
    y = y_list[i]
    j = shi_map2[p].index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
shi_map = sorted(shi_map.items(), key=lambda x: x[0])
shi_map = dict(shi_map)
shi_map2 = {}
for k, v in shi_map.items():
    v = sorted(v)
    shi_map2[k] = v

for i in range(M):
    p = p_list[i]
    y = y_list[i]
    j = shi_map2[p].index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
shi_map = sorted(shi_map.items(), key=lambda x: x[0])
shi_map = dict(shi_map)
count_p = len(set(p_list))
shi_list = list(map(sorted, shi_map.values()))
for i in range(M):
    p = p_list[i]
    y = y_list[i]
    if p > count_p:
        s = shi_list[p - 2 - count_p]
    else:
        s = shi_list[p-1]
    j = s.index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
count_p = len(set(p_list))
shi_list = list(map(sorted, shi_map.values()))
for i in range(M):
    p = p_list[i]
    y = y_list[i]
    if p > count_p:
        s = shi_list[p - 1 - count_p]
    else:
        s = shi_list[p-1]
    j = s.index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

p_list = []
y_list = []
shi_map = {}

for i in range(M):
    p, y = map(int, input().split())
    p_list.append(p)
    y_list.append(y)
    if p in shi_map:
        shi_map[p].append(y)
    else:
        shi_map[p] = [y]
count_p = len(set(p_list))
shi_list = list(map(sorted, shi_map.values()))
for i in range(M):
    p = p_list[i]
    y = y_list[i]
    s = shi_list[p-1-count_p]
    j = s.index(y)
    p_str = str(p).zfill(6)
    j_str = str(j+1).zfill(6)
    print(p_str + j_str)



Fixed submission:
N, M = map(int, input().split())

shi_map = []

for i in range(M):
    p, y = map(int, input().split())
    shi_map.append([i, p, y])

shi_map = sorted(shi_map, key=lambda x: (x[1], x[2]))

result = {}
shi_count = {}
for i, p, y in shi_map:

    if p in shi_count:
        c = shi_count[p]
        count = c + 1
        shi_count[p] = count
    else:
        shi_count[p] = 1
        count = 1
    result[i] = [p, count]
result = list(sorted(result.items(), key=lambda x: x[0]))

for i, p in result:

    p2 = str(p[0]).zfill(6)

    y = str(p[1]).zfill(6)
    r = p2+y
    print(r)