Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys


def input(): return sys.stdin.readline()[:-1]


sys.setrecursionlimit(10**8)
INF = 1001001001001
n, m, l = map(int, input().split())
D = [[INF]*n for i in range(n)]

for i in range(m):
    a, b, c = map(int, input().split())
    D[a-1][b-1] = c
    D[b-1][a-1] = c

for k in range(n):
    for i in range(n):
        for j in range(n):
            D[i][j] = min(D[i][j], D[i][k]+D[k][j])


for i in range(n):
    for j in range(n):
        D[i][j] = 1 if D[i][j] <= l else INF

for k in range(n):
    for i in range(n):
        for j in range(n):
            D[i][j] = min(D[i][j], D[i][k]+D[k][j])
# for i in D:
#     print(i)

q = int(input())
for i in range(q):
    s, g = map(int, input().split())
    s -= 1
    g -= 1
    print(D[s][g]-1 if D[s][g] != INF else -1)


Fixed submission:
#!/usr/bin/env python3
import sys
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, dijkstra
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

# f = floyd_warshall(G,directed=True(有向か、defaultはTrue))
# d = dijkstra(G, indices=0,directed=True(有向か、defaultはTrue))
n,m,l=map(int,input().split())
rinsetsu=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    rinsetsu[a-1][b-1]=c
    rinsetsu[b-1][a-1]=c

# G = csgraph_from_dense(rinsetsu, null_value=0)
f = floyd_warshall(rinsetsu,directed=True)
# print(f)
for i in range(n):
    for j in range(n):
        f[i][j]= 1 if 1<=f[i][j]<=l else 0
# print(f)
f2= floyd_warshall(f,directed=True)

q = int(input())
for i in range(q):
    s,g=map(int,input().split())
    s-=1;g-=1
    print(int(f2[s][g])-1 if f2[s][g]!=float("inf") else -1)

# print(f2)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
INF = 100100100
n, m, l = map(int, input().split())
rinsetsu = [[INF]*n for i in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    rinsetsu[a-1][b-1] = c
    rinsetsu[b-1][a-1] = c
for k in range(n):
    for i in range(n):
        for j in range(n):
            rinsetsu[i][j]=min(rinsetsu[i][j],rinsetsu[i][k]+rinsetsu[j][k])
for i in range(n):
    for j in range(n):
        rinsetsu[i][j]=1 if rinsetsu[i][j]<=l else INF
for k in range(n):
    for i in range(n):
        for j in range(n):
            rinsetsu[i][j] = min(rinsetsu[i][j], rinsetsu[i][k]+rinsetsu[j][k])
q=int(input())
for i in range(q):
    s,g=map(int,input().split())
    s-=1;g-=1
    print(rinsetsu[s][g]-1 if rinsetsu[i][j]!=INF else -1)



Fixed submission:
#!/usr/bin/env python3
import sys
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, dijkstra
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

# f = floyd_warshall(G,directed=True(有向か、defaultはTrue))
# d = dijkstra(G, indices=0,directed=True(有向か、defaultはTrue))
n,m,l=map(int,input().split())
rinsetsu=[[0]*n for i in range(n)]
for i in range(m):
    a,b,c=map(int,input().split())
    rinsetsu[a-1][b-1]=c
    rinsetsu[b-1][a-1]=c

# G = csgraph_from_dense(rinsetsu, null_value=0)
f = floyd_warshall(rinsetsu,directed=True)
# print(f)
for i in range(n):
    for j in range(n):
        f[i][j]= 1 if 1<=f[i][j]<=l else 0
# print(f)
f2= floyd_warshall(f,directed=True)

q = int(input())
for i in range(q):
    s,g=map(int,input().split())
    s-=1;g-=1
    print(int(f2[s][g])-1 if f2[s][g]!=float("inf") else -1)

# print(f2)