Buggy python submission (verdict: Runtime Error):
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Fixed submission:
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, raw_input().split())

P=[]
Y=[]
for i in range(M):
	P_tmp,Y_tmp = map(int, raw_input().split())
	P.append(P_tmp)
	Y.append(Y_tmp)

S={}

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	try:
		S[key]
	except:
		S[key]=[]
	S[key].append(i)

for i in S.keys():
	S[i]=sorted(S[i])

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	print "{0:06d}".format(P[Y.index(i)]) + "{0:06d}".format(S[key].index(i)+1)

Fixed submission:
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, raw_input().split())

P=[]
Y=[]
for i in range(M):
	P_tmp,Y_tmp = map(int, raw_input().split())
	P.append(P_tmp)
	Y.append(Y_tmp)

S={}

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	#print "key: "+key
	try:
		S[key]
	except:
		S[key]=[]
	S[key].append(i)

for i in S.keys():
	S[i]=sorted(S[i])

#print S

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	print "{0:06d}".format(P[Y.index(i)]) + "{0:06d}".format(S[key].index(i)+1)



Fixed submission:
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, raw_input().split())

P=[]
Y=[]
for i in range(M):
	P_tmp,Y_tmp = map(int, raw_input().split())
	P.append(P_tmp)
	Y.append(Y_tmp)

S={}

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	#print "key: "+key
	try:
		S[key]
	except:
		S[key]=[]
	S[key].append(i)

for i in S.keys():
	S[i]=sorted(S[i])

#print S

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	print "{0:06d}".format(P[Y.index(i)]) + "{0:06d}".format(S[key].index(i)+1)

Fixed submission:
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, raw_input().split())

P=[]
Y=[]
for i in range(M):
	P_tmp,Y_tmp = map(int, raw_input().split())
	P.append(P_tmp)
	Y.append(Y_tmp)

S={}

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	#print "key: "+key
	try:
		S[key]
	except:
		S[key]=[]
	S[key].append(i)

for i in S.keys():
	S[i]=sorted(S[i])

#print S

for i in Y:
	key = str(P[Y.index(i)]) + "_"
	print "{0:06d}".format(P[Y.index(i)]) + "{0:06d}".format(S[key].index(i)+1)



Fixed submission:
from collections import defaultdict as dd
 
d=dd(int)
n,m=map(int,input().split())
l=[[i]+list(map(int,input().split()))+[0] for i in range(m)]
 
o=sorted(l,key=lambda x:x[2])
for i,j in enumerate(o):
  d[j[1]]+=1
  o[i][3]=d[j[1]]
 
for i in sorted(o):
  print('{0:06d}'.format(i[1])+'{0:06d}'.format(i[3]))