Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  dic.setdefault(P, list())
  dic[P].append(Y)
for i in dic.keys():
    dic[i].sort()
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Fixed submission:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y, i])
raw.sort()
for i in range(M):
  if i == 0:
    raw[i][1] = 1
    p, y, ind = raw[i]
    continue
  pp, yy, iind = raw[i]
  if pp == p:
    raw[i][1] = y + 1
  else:
    raw[i][1] = 1
  p, y, ind = raw[i]
raw.sort(key = lambda x:x[2])
for r in raw:
    p, y, ind = r
    P = "{0:06d}".format(p)
    Y = "{0:06d}".format(y)
    print(P+Y)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  dic.setdefault(P, list())
  dic[P].append(Y)
for i in dic.keys():
  try:
    dic[i].sort()
  except:
    continue
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Fixed submission:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y, i])
raw.sort()
for i in range(M):
  if i == 0:
    raw[i][1] = 1
    p, y, ind = raw[i]
    continue
  pp, yy, iind = raw[i]
  if pp == p:
    raw[i][1] = y + 1
  else:
    raw[i][1] = 1
  p, y, ind = raw[i]
raw.sort(key = lambda x:x[2])
for r in raw:
    p, y, ind = r
    P = "{0:06d}".format(p)
    Y = "{0:06d}".format(y)
    print(P+Y)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  dic.setdefault(P, list())
  dic[P].append(Y)
for i in range(1, N+1):
  try:
    dic[i].sort()
  except:
    continue
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Fixed submission:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y, i])
raw.sort()
for i in range(M):
  if i == 0:
    raw[i][1] = 1
    p, y, ind = raw[i]
    continue
  pp, yy, iind = raw[i]
  if pp == p:
    raw[i][1] = y + 1
  else:
    raw[i][1] = 1
  p, y, ind = raw[i]
raw.sort(key = lambda x:x[2])
for r in raw:
    p, y, ind = r
    P = "{0:06d}".format(p)
    Y = "{0:06d}".format(y)
    print(P+Y)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y])
  if not dic.get(P):
    dic[P] = list() 
  dic[P].append(Y)
for i in range(1, N+1):
  try:
    dic[i].sort()
  except:
    continue
for i in range(M):
  P, Y = raw[i]
  ind = dic[P].index(Y)
  P = "{0:06d}".format(P)
  Y = "{0:06d}".format(ind+1)
  print(P+Y)

Fixed submission:
N, M = map(int, input().split())
dic = {}
raw = []
dic[1] = []
for i in range(M):
  P, Y = map(int, input().split())
  raw.append([P, Y, i])
raw.sort()
for i in range(M):
  if i == 0:
    raw[i][1] = 1
    p, y, ind = raw[i]
    continue
  pp, yy, iind = raw[i]
  if pp == p:
    raw[i][1] = y + 1
  else:
    raw[i][1] = 1
  p, y, ind = raw[i]
raw.sort(key = lambda x:x[2])
for r in raw:
    p, y, ind = r
    P = "{0:06d}".format(p)
    Y = "{0:06d}".format(y)
    print(P+Y)