Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(m)]
pf = [(i, []) for i in range(100010)]
for p,y in lst:
    pf[p][1].append(y)
for i in range(len(pf)):
    l = sorted(pf[i][1])
    pf[i] = (i, l)
for p,y in lst:
    print(str(p).zfill(6)+str(pf[p][1].index(y)+1).zfill(6))

Fixed submission:
n,m = map(int,input().split())
city_inf = []
for i in range(m):
    array = [i]
    array.extend(list(map(int,input().split())))
    city_inf.append(array)

city_inf.sort(key=lambda x:x[2])
order_counter = {}

for list in city_inf:
    if list[1] in order_counter.keys():
        order_counter[list[1]] += 1
        list.append(order_counter[list[1]])
    else:
        order_counter[list[1]] = 1
        list.append(1)

city_inf.sort(key=lambda x:x[0])
zero_p = ''
zero_y = ''
for list in city_inf:
    zero_p = '0'*(6-len(str(list[1])))
    zero_y = '0'*(6-len(str(list[3])))
    list.append(zero_p + str(list[1]) + zero_y + str(list[3]))
    print(list[4])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
lst = [list(map(int,input().split())) for _ in range(m)]

x = sorted(lst, key=lambda x:x[1])
dic = {}
for p,y in x:
    if p in dic.keys():
        dic[p].append(y)
    else:
        dic[p] = [y]
for p,y in lst:
    print(str(p).zfill(6)+str(dic[p].index(y)+1).zfill(6))

Fixed submission:
n,m = map(int,input().split())
city_inf = []
for i in range(m):
    array = [i]
    array.extend(list(map(int,input().split())))
    city_inf.append(array)

city_inf.sort(key=lambda x:x[2])
order_counter = {}

for list in city_inf:
    if list[1] in order_counter.keys():
        order_counter[list[1]] += 1
        list.append(order_counter[list[1]])
    else:
        order_counter[list[1]] = 1
        list.append(1)

city_inf.sort(key=lambda x:x[0])
zero_p = ''
zero_y = ''
for list in city_inf:
    zero_p = '0'*(6-len(str(list[1])))
    zero_y = '0'*(6-len(str(list[3])))
    list.append(zero_p + str(list[1]) + zero_y + str(list[3]))
    print(list[4])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
dic = {}
lst = [list(map(int,input().split())) for _ in range(m)]
for p,y in lst:
    if p in dic.keys():
        dic[p].append(y)
    else:
        dic[p] = [y]
nx_dic = {}
for k, v in dic.items():
    nx_dic[k] = sorted(v)

for p,y in lst:
    print(str(p).zfill(6)+str(nx_dic[p].index(y)+1).zfill(6))

Fixed submission:
n,m = map(int,input().split())
city_inf = []
for i in range(m):
    array = [i]
    array.extend(list(map(int,input().split())))
    city_inf.append(array)

city_inf.sort(key=lambda x:x[2])
order_counter = {}

for list in city_inf:
    if list[1] in order_counter.keys():
        order_counter[list[1]] += 1
        list.append(order_counter[list[1]])
    else:
        order_counter[list[1]] = 1
        list.append(1)

city_inf.sort(key=lambda x:x[0])
zero_p = ''
zero_y = ''
for list in city_inf:
    zero_p = '0'*(6-len(str(list[1])))
    zero_y = '0'*(6-len(str(list[3])))
    list.append(zero_p + str(list[1]) + zero_y + str(list[3]))
    print(list[4])

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
dic = {}
lst = [list(map(int,input().split())) for _ in range(m)]
for p,y in lst:
    if p in dic.keys():
        dic[p].append(y)
    else:
        dic[p] = [y]
nx_dic = {}
for k, v in dic.items():
    nx_dic[k] = sorted(v)

for p,y in lst:
    print(str(p).zfill(6)+str(nx_dic[p].index(y)+1).zfill(6))

Fixed submission:
n,m = map(int,input().split())
city_inf = []
for i in range(m):
    array = [i]
    array.extend(list(map(int,input().split())))
    city_inf.append(array)

city_inf.sort(key=lambda x:x[2])
order_counter = {}

for list in city_inf:
    if list[1] in order_counter.keys():
        order_counter[list[1]] += 1
        list.append(order_counter[list[1]])
    else:
        order_counter[list[1]] = 1
        list.append(1)

city_inf.sort(key=lambda x:x[0])
zero_p = ''
zero_y = ''
for list in city_inf:
    zero_p = '0'*(6-len(str(list[1])))
    zero_y = '0'*(6-len(str(list[3])))
    list.append(zero_p + str(list[1]) + zero_y + str(list[3]))
    print(list[4])

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(m)]
order = sorted(lst , key=lambda x:(x[0],x[1]))
mydict = {}

c = 1
for i in range(len(order)-1):
    mydict[str(order[i])] = c
    if order[i][0] == order[i+1][0]:
        c += 1
    else:
        c = 1
if order[m-1][0] == order[m-2][0]:
    mydict[str(order[m-1])] = order[m-2][2]+1
else:
    mydict[str(order[m-1])] = 1

for i in range(m):
    val = mydict[str(lst[i])]
    p = lst[i][0]
    s='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(val)))+str(val)
    print(s)


Fixed submission:
n,m = map(int,input().split())
city_inf = []
for i in range(m):
    array = [i]
    array.extend(list(map(int,input().split())))
    city_inf.append(array)

city_inf.sort(key=lambda x:x[2])
order_counter = {}

for list in city_inf:
    if list[1] in order_counter.keys():
        order_counter[list[1]] += 1
        list.append(order_counter[list[1]])
    else:
        order_counter[list[1]] = 1
        list.append(1)

city_inf.sort(key=lambda x:x[0])
zero_p = ''
zero_y = ''
for list in city_inf:
    zero_p = '0'*(6-len(str(list[1])))
    zero_y = '0'*(6-len(str(list[3])))
    list.append(zero_p + str(list[1]) + zero_y + str(list[3]))
    print(list[4])

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(m)]
order = sorted(lst , key=lambda x:(x[0],x[1]))

c = 1
for i in range(len(order)-1):
    order[i].append(c)
    if order[i][0] == order[i+1][0]:
        c += 1
    else:
        c = 1
if order[m-1][0] == order[m-2][0]:
    order[m-1].append(order[m-2][2]+1)
else:
    order[m-1].append(1)


for i in range(m):
    p,y = lst[i][0],lst[i][1]
    for odr in order:
        if odr[0]==p and odr[1]==y:
            x = odr[2]
    s='0'*(6-len(str(p)))+str(p)+'0'*(6-len(str(x)))+str(x)
    print(s)
    

Fixed submission:
n,m = map(int,input().split())
city_inf = []
for i in range(m):
    array = [i]
    array.extend(list(map(int,input().split())))
    city_inf.append(array)

city_inf.sort(key=lambda x:x[2])
order_counter = {}

for list in city_inf:
    if list[1] in order_counter.keys():
        order_counter[list[1]] += 1
        list.append(order_counter[list[1]])
    else:
        order_counter[list[1]] = 1
        list.append(1)

city_inf.sort(key=lambda x:x[0])
zero_p = ''
zero_y = ''
for list in city_inf:
    zero_p = '0'*(6-len(str(list[1])))
    zero_y = '0'*(6-len(str(list[3])))
    list.append(zero_p + str(list[1]) + zero_y + str(list[3]))
    print(list[4])