Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[float('inf')]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c
G = csgraph_from_dense(E, null_value=10**10)
d = floyd_warshall(G)
E=[[1 if __<= L else 10**10 for __ in _] for _ in d]
G = csgraph_from_dense(E, null_value=10**10)
E = floyd_warshall(G)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Fixed submission:
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[10**10]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c
G = csgraph_from_dense(E, null_value=10**10)
d = floyd_warshall(G)
E=[[1 if __<= L else 10**10 for __ in _] for _ in d]
G = csgraph_from_dense(E, null_value=10**10)
E = floyd_warshall(G)

for s,t in ST:
    if np.isinf(E[s-1][t-1]):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Fixed submission:
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[10**10]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c
G = csgraph_from_dense(E, null_value=10**10)
d = floyd_warshall(G)
E=[[1 if __<= L else 10**10 for __ in _] for _ in d]
G = csgraph_from_dense(E, null_value=10**10)
E = floyd_warshall(G)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Fixed submission:
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Buggy python submission (verdict: Time Limit Exceeded):
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[-1]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c

def warshall_floyd(V,E):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if E[i][j] == -1:
                    if (E[i][k] != -1) and (E[k][j] != -1):
                        E[i][j]=E[i][k]+E[k][j]
                elif E[i][k] == -1 or E[k][j] == -1:
                    pass
                else:
                    E[i][j]=min(E[i][j],E[i][k]+E[k][j])
    return E

E=warshall_floyd(N,E)
for i in range(N):
    E[i][i]=-1
E=[[1 if __<= L and __!= -1 else -1 for __ in _] for _ in E]
E=warshall_floyd(N,E)


for s,t in ST:
    if E[s-1][t-1]>0:
        print(E[s-1][t-1]-1)
    else:
        print(-1)

Fixed submission:
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
A=[0]*M
B=[0]*M
C=[0]*M
for i in range(M):
    A[i],B[i],C[i] = map(int,input().split())
    A[i] -=1
    B[i] -=1
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))