Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
   input = sys.stdin.buffer.readline
   n,m = map(int, input().split())
   results = {}
   p_list=[]
   y_list=[]
   cnt = 0
   for i in range(m):
       p,y = map(int, input().split())
       p_list.append(p)
       y_list.append(y)
       if results.get(p) is None:
           results[p] = [y]
       else:
           results[p].append(y)
   for i ,p in enumerate(p_list):
       p_sort = sorted(results[p])
       import bisect
       print('{:006}'.format(p)+'{:006}'.format(bisect.bisect_left(p_sort,y_list[i])+1))
if __name__ == "__main__":
    main()

Fixed submission:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]

convertedPY = [
    {'index': i,
     'city': py[0],
     'year': py[1]
     } for i, py in enumerate(PY)
]
'''
3 4
1 32
3 64
3 63
1 33

'''
convertedPY = sorted(convertedPY, key=lambda a: (a['city'], a['year']))
answer = []
cnt = 0
tmp = convertedPY[0]['city']
#print(convertedPY)
result = []
for py in convertedPY:
    #print(tmp)
    temp_dict = {}
    if tmp == py['city']:
        cnt += 1
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
    else:
        cnt = 1
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
        tmp = py['city']


result = sorted(result, key=lambda a: a['index'])
#print(result)
for r in result:
    print(r['answer'])

'''
3
21 -11
81234 52141 94124
'''

#print(PY)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
   input = sys.stdin.buffer.readline
   n,m = map(int, input().split())
   results = {}
   p_list=[]
   y_list=[]
   cnt = 0
   for i in range(m):
       p,y = map(int, input().split())
       p_list.append(p)
       y_list.append(y)
       if results.get(p) is None:
           results[p] = [y]
       else:
           results[p].append(y)
   for i in p_list:
       p_sort = sorted(results[i])
       print('{:006}'.format(i)+'{:006}'.format(p_sort.index(y_list[cnt])+1))
       cnt+=1
if __name__ == "__main__":
    main()

Fixed submission:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]

convertedPY = [
    {'index': i,
     'city': py[0],
     'year': py[1]
     } for i, py in enumerate(PY)
]
'''
3 4
1 32
3 64
3 63
1 33

'''
convertedPY = sorted(convertedPY, key=lambda a: (a['city'], a['year']))
answer = []
cnt = 0
tmp = convertedPY[0]['city']
#print(convertedPY)
result = []
for py in convertedPY:
    #print(tmp)
    temp_dict = {}
    if tmp == py['city']:
        cnt += 1
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
    else:
        cnt = 1
        temp_dict['answer'] = '{:0=6}'.format(py['city']) + '{:0=6}'.format(cnt)
        temp_dict['index'] = py['index']
        result.append(temp_dict)
        tmp = py['city']


result = sorted(result, key=lambda a: a['index'])
#print(result)
for r in result:
    print(r['answer'])

'''
3
21 -11
81234 52141 94124
'''

#print(PY)