Buggy python submission (verdict: Time Limit Exceeded):
import copy

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
S = copy.deepcopy(L)
S.sort()
A = [[] for i in range(N)]
k = 0
j = 1
while (k < M):
  if (S[k][0] == j):
    A[j-1].append(S[k][1])
    k += 1
  else:
    j = S[k][0]
    A[j-1].append(S[k][1])
    k += 1
    
p = 0    
for i in range(M):
  if (L[i][1] in A[L[i][0]-1]):
    p = A[L[i][0]-1].index(L[i][1])+1
  print(str('0'*(6-len(str(L[i][0]))))+str(L[i][0])+str('0'*(6-len(str(p))))+str(p))

Fixed submission:
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    cnt += 1
    L[k].append(cnt)
  else:
    l = L[k][0]
    cnt = 1
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3]))

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
S = copy.deepcopy(L)
S.sort()
A = [[] for i in range(N)]
k = 0
j = 1
while (k < M):
  if (S[k][0] == j):
    A[j-1].append(S[k][1])
    k += 1
  else:
    j = S[k][0]
    A[j-1].append(S[k][1])
    k += 1     
for i in range(M):
  if (L[i][1] in A[L[i][0]-1]):
    print(str('0'*(6-len(str(L[i][0]))))+str(L[i][0])+str('0'*(6-len(str(A[L[i][0]-1].index(L[i][1])+1))))+str(A[L[i][0]-1].index(L[i][1])+1))

Fixed submission:
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    cnt += 1
    L[k].append(cnt)
  else:
    l = L[k][0]
    cnt = 1
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3]))

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
S = copy.deepcopy(L)
S.sort()
A = [[] for i in range(N)]
k = 0
j = 1
while (k < M):
  if (S[k][0] == j):
    A[j-1].append(S[k][1])
    k += 1
  else:
    j = S[k][0]
    A[j-1].append(S[k][1])
    k += 1
    
p = 0    
for i in range(M):
  if (L[i][1] in A[L[i][0]-1]):
    p = A[L[i][0]-1].index(L[i][1])+1
  print(str('0'*(6-len(str(L[i][0]))))+str(L[i][0])+str('0'*(6-len(str(p))))+str(p))

Fixed submission:
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    cnt += 1
    L[k].append(cnt)
  else:
    l = L[k][0]
    cnt = 1
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3]))

Buggy python submission (verdict: Time Limit Exceeded):
import copy

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
S = copy.deepcopy(L)
S.sort()
A = [[] for i in range(N)]
k = 0
j = 1
while (k < M):
  if (S[k][0] == j):
    A[j-1].append(S[k][1])
    k += 1
  else:
    j = S[k][0]
    A[j-1].append(S[k][1])
    k += 1
    
p = 0    
for i in range(M):
  if (L[i][1] in A[L[i][0]-1]):
    p = A[L[i][0]-1].index(L[i][1])+1
  print(str('0'*(6-len(str(L[i][0]))))+str(L[i][0])+str('0'*(6-len(str(p))))+str(p))

Fixed submission:
N,M = map(int,input().split())
L = []
for i in range(M):
  L.append(list(map(int,input().split())))
for j in range(M):
  L[j].append(j)
L.sort()
l = L[0][0]
cnt = 0
for k in range(M):
  if l == L[k][0]:
    cnt += 1
    L[k].append(cnt)
  else:
    l = L[k][0]
    cnt = 1
    L[k].append(cnt)
L = sorted(L, key = lambda x:x[2])
for i in range(M):
  print('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(L[i][3])))+str(L[i][3]))