Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n, m = map(int, input().split())
  def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
  lst = [[-1] for i in range(n + 1)]
  cities = []
  for i in range(m):
    temp = tuple(map(int, input().split()))
    lst[temp[0]].append(temp[1])
    cities.append(temp)
  for l in lst:
    l.sort()
  for tpl in cities:
    a = lst[tpl[0]].index(tpl[1])
    print(zs(tpl[0]) + zs(a))
if __name__ == '__main__':
  main()

Fixed submission:
n, m = map(int, input().split())
def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
lst = []
for i in range(m):
  lst.append(tuple(map(int, input().split())))
slst = sorted(lst)
dic = {}
temp = 0
for i in range(m):
  if slst[i][0] == slst[i - 1][0]:
    temp += 1
  else:
    temp = 1
  dic[slst[i]] = zs(slst[i][0]) + zs(temp)
for i in lst:
  print(dic[i])

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n, m = map(int, input().split())
  def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
  lst = [[-1] for i in range(n + 1)]
  cities = []
  for i in range(m):
    temp = tuple(map(int, input().split()))
    lst[temp[0]].append(temp[1])
    cities.append(temp)
  for l in lst:
    l.sort()
  for tpl in cities:
    a = lst[tpl[0]].index(tpl[1])
    print(zs(tpl[0]) + zs(a))
if __name__ == '__main__':
  main()

Fixed submission:
n, m = map(int, input().split())
def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
lst = []
for i in range(m):
  lst.append(tuple(map(int, input().split())))
slst = sorted(lst)
dic = {}
temp = 0
for i in range(m):
  if slst[i][0] == slst[i - 1][0]:
    temp += 1
  else:
    temp = 1
  dic[slst[i]] = zs(slst[i][0]) + zs(temp)
for i in lst:
  print(dic[i])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
def zs(num):
  k = 6 - len(str(num))
  return '0' * k + str(num)
lst = [[-1] for i in range(n + 1)]
cities = []
for i in range(m):
  temp = tuple(map(int, input().split()))
  lst[temp[0]].append(temp[1])
  cities.append(temp)
for l in lst:
  l.sort()
for tpl in cities:
  a = lst[tpl[0]].index(tpl[1])
  print(zs(tpl[0]) + zs(a))

Fixed submission:
n, m = map(int, input().split())
def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
lst = []
for i in range(m):
  lst.append(tuple(map(int, input().split())))
slst = sorted(lst)
dic = {}
temp = 0
for i in range(m):
  if slst[i][0] == slst[i - 1][0]:
    temp += 1
  else:
    temp = 1
  dic[slst[i]] = zs(slst[i][0]) + zs(temp)
for i in lst:
  print(dic[i])

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
def zs(num):
  k = 6 - len(str(num))
  return '0' * k + str(num)
lst = [[-1] for i in range(n + 1)]
cities = []
for i in range(m):
  temp = tuple(map(int, input().split()))
  lst[temp[0]].append(temp[1])
  cities.append(temp)
for l in lst:
  l.sort()
for tpl in cities:
  a = lst[tpl[0]].index(tpl[1])
  print(zs(tpl[0]) + zs(a))

Fixed submission:
n, m = map(int, input().split())
def zs(num):
    k = 6 - len(str(num))
    return '0' * k + str(num)
lst = []
for i in range(m):
  lst.append(tuple(map(int, input().split())))
slst = sorted(lst)
dic = {}
temp = 0
for i in range(m):
  if slst[i][0] == slst[i - 1][0]:
    temp += 1
  else:
    temp = 1
  dic[slst[i]] = zs(slst[i][0]) + zs(temp)
for i in lst:
  print(dic[i])