Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p, y])
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)
sorted_data = {i: sorted(j) for i, j in sorted_data.items()}

for i in range(M):
    rank = sorted_data[data[i][0]].index(data[i][1]) + 1
    print(str(data[i][0]).zfill(6) + str(rank).zfill(6))

Fixed submission:
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = [int(i) for i in input().split()]
data = list()
data_dict = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
for p, y in sorted(data,key=lambda x:x[1]):
    if data_dict.get(p) is None:
        data_dict[p] = []
    data_dict[p].append(y)

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for p, y in data:
    rank = data_dict[p].index(y) + 1
    print(num2str(p) + num2str(rank))

Fixed submission:
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
N , M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
for p, y in sorted(data):
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for p, y in data:
    rank = sorted_data[p].index(y) + 1
    print(num2str(p) + num2str(rank))

Fixed submission:
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
N , M = [int(i) for i in input().split()]
data = list()
sorted_data = dict()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([p,y])
    if sorted_data.get(p) is None:
        sorted_data[p] = []
    sorted_data[p].append(y)
sorted_data = {i:sorted(j) for i,j in sorted_data.items()}

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for i in range(M):
    rank = sorted_data[data[i][0]].index(data[i][1]) + 1
    print(num2str(data[i][0]) + num2str(rank))

Fixed submission:
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
N , M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    data.append([int(i) for i in input().split()])
sorted_data = dict()
for i in data:
    if sorted_data.get(i[0]) is None:
        sorted_data[i[0]] = []
    sorted_data[i[0]].append(i[1])
sorted_data = {i:sorted(j) for i,j in sorted_data.items()}

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for i in range(M):
    rank = sorted_data[data[i][0]].index(data[i][1]) + 1
    print(num2str(data[i][0]) + num2str(rank))

Fixed submission:
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))

Buggy python submission (verdict: Time Limit Exceeded):
N , M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    data.append([int(i) for i in input().split()])
sorted_data = sorted(data, key=lambda x:x[1])

def num2str(num, len_str=6):
    return "0" * (len_str - len(str(num))) + str(num)

for i in range(M):
    rank = [j[1] for j in sorted_data if j[0] == data[i][0]].index(data[i][1])
    print(num2str(data[i][0]) + num2str(rank+1))

Fixed submission:
N, M = [int(i) for i in input().split()]
data = list()
for i in range(M):
    p, y = [int(i) for i in input().split()]
    data.append([i, p, y])
data.sort(key=lambda x:(x[1],x[2]))
ind = 1
for j, (i, p, y) in enumerate(data):
    if data[j-1][1] != p:
        ind = 1
    data[j].append(ind)
    ind += 1
data.sort(key=lambda x:x[0])
for i, p, y, j in data:
    print(str(p).zfill(6) + str(j).zfill(6))