Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = X + Y#文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])
  


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

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = str(X) + str(Y) #文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = X + Y#文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])
  


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

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = str(X) + str(Y) #文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY[i][0] == PY[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY[i][1] = X + Y#文字列の結合
#print(PY)
PY = sorted(PY, key = lambda x:x[2])

for i in range(M):
  print(PY[i][1])

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

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = str(X) + str(Y) #文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY = sorted(PY)

ans = [0]*M
#print(PY)

for i in range(M):
  X = str(PY[i][0])
  if i >= 1:
    #print(PY)
    if PY[i][0] == PY[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY[i][1] = X + Y
#print(PY)
PY = sorted(PY, key = lambda x:x[2])

for i in range(M):
  print(PY[i][1])

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

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = str(X) + str(Y) #文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])