Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
P = []

Indexs = []
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs.append(y)
	Syuturyoku.append(("0","0"))

for i in range(len(P)):
	P[i].sort()
	# P[i] = list(map(str,P[i]))


for i in range(len(P)):
	if(len(P[i])>1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			# si = str(si)
			x = j+1
			# x = str(x)
			# bangou = list(map(str,si))
			# bangou_len = int(len(bangou))
			# bangou_ushiro = list(map(str,x))
			# bangou_ushiro_len = int(len(bangou_ushiro))
			# if(len(bangou)<6):
			# 	for zero in range(6-bangou_len):
			# 		bangou.insert(0,'0')
			# if(len(bangou_ushiro)<6):
			# 	for zero in range(6-bangou_ushiro_len):
			# 		bangou_ushiro.insert(0,'0')

			# mojiretsu = ''
			# for k in bangou:
			# 	mojiretsu += k
			# mojiretsu2 = ''
			# for k2 in bangou_ushiro:
			# 	mojiretsu2 += k2

			a = Indexs.index(atai)
			Syuturyoku[a] = (si, x)
for i in range(M):
	print('{0:06}{1:06}'.format(Syuturyoku[i][0], Syuturyoku[i][1]))


Fixed submission:
N,M = map(int,input().split())
P = []

Indexs = {}
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs[y] = i
	Syuturyoku.append(0)

for i in range(len(P)):
	P[i].sort()
	# P[i] = list(map(str,P[i]))


for i in range(N):
	if (len(P[i]) > 1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			# si = str(si)
			x = j+1
			# x = str(x)
			# bangou = list(map(str,si))
			# bangou_len = int(len(bangou))
			# bangou_ushiro = list(map(str,x))
			# bangou_ushiro_len = int(len(bangou_ushiro))
			# if(len(bangou)<6):
			# 	for zero in range(6-bangou_len):
			# 		bangou.insert(0,'0')
			# if(len(bangou_ushiro)<6):
			# 	for zero in range(6-bangou_ushiro_len):
			# 		bangou_ushiro.insert(0,'0')

			# mojiretsu = ''
			# for k in bangou:
			# 	mojiretsu += k
			# mojiretsu2 = ''
			# for k2 in bangou_ushiro:
			# 	mojiretsu2 += k2

			a = Indexs[atai]
			Syuturyoku[a] = (si, x)

for i in range(M):
	print('{0:06}{1:06}'.format(Syuturyoku[i][0], Syuturyoku[i][1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
P = []

Indexs = []
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs.append(y)
	Syuturyoku.append(("0","0"))

for i in range(len(P)):
	P[i].sort()
	P[i] = list(map(str,P[i]))


for i in range(len(P)):
	if(len(P[i])>1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			si = str(si)
			x = j+1
			x = str(x)
			bangou = list(map(str,si))
			bangou_len = int(len(bangou))
			bangou_ushiro = list(map(str,x))
			bangou_ushiro_len = int(len(bangou_ushiro))
			if(len(bangou)<6):
				for zero in range(6-bangou_len):
					bangou.insert(0,'0')
			if(len(bangou_ushiro)<6):
				for zero in range(6-bangou_ushiro_len):
					bangou_ushiro.insert(0,'0')

			mojiretsu = ''
			for k in bangou:
				mojiretsu += k
			mojiretsu2 = ''
			for k2 in bangou_ushiro:
				mojiretsu2 += k2

			a = Indexs.index(int(atai))
			Syuturyoku[a] = (mojiretsu,mojiretsu2)
for i in range(M):
	print(Syuturyoku[i][0]+Syuturyoku[i][1])


Fixed submission:
N,M = map(int,input().split())
P = []

Indexs = {}
Syuturyoku = []


for j in range(N):
	P.append([0])


for i in range(M):
	p,y = map(int,input().split())

	P[p-1].append(y)
	Indexs[y] = i
	Syuturyoku.append(0)

for i in range(len(P)):
	P[i].sort()
	# P[i] = list(map(str,P[i]))


for i in range(N):
	if (len(P[i]) > 1):
		for j in range(len(P[i])-1):
			atai = P[i][j+1]
			si = i+1
			# si = str(si)
			x = j+1
			# x = str(x)
			# bangou = list(map(str,si))
			# bangou_len = int(len(bangou))
			# bangou_ushiro = list(map(str,x))
			# bangou_ushiro_len = int(len(bangou_ushiro))
			# if(len(bangou)<6):
			# 	for zero in range(6-bangou_len):
			# 		bangou.insert(0,'0')
			# if(len(bangou_ushiro)<6):
			# 	for zero in range(6-bangou_ushiro_len):
			# 		bangou_ushiro.insert(0,'0')

			# mojiretsu = ''
			# for k in bangou:
			# 	mojiretsu += k
			# mojiretsu2 = ''
			# for k2 in bangou_ushiro:
			# 	mojiretsu2 += k2

			a = Indexs[atai]
			Syuturyoku[a] = (si, x)

for i in range(M):
	print('{0:06}{1:06}'.format(Syuturyoku[i][0], Syuturyoku[i][1]))