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

def wf(d):
  for i in range(n):
    for j in range(n):#start
      for k in range(n):#end
        d[j][k]=min(d[j][k], d[j][i] + d[i][k])
  return d

n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
  d[i][i] = 0
  e[i][i] = 0

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

d=wf(d)
for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1

e=wf(e)

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(e[s-1][t-1]-1)

Fixed submission:
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
  d[i][i] = 0
  e[i][i] = 0

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

d=floyd_warshall(csr_matrix(d))
for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1

e=floyd_warshall(csr_matrix(e))

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(int(e[s-1][t-1]-1))

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

def wf(d):
  for i in range(n):
    for j in range(n):#start
      for k in range(n):#end
        d[j][k]=min(d[j][k], d[j][i] + d[i][k])
  return d

n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
  d[i][i] = 0
  e[i][i] = 0

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

d=wf(d)
for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1

e=wf(e)

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(e[s-1][t-1]-1)


Fixed submission:
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
  d[i][i] = 0
  e[i][i] = 0

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

d=floyd_warshall(csr_matrix(d))
for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1

e=floyd_warshall(csr_matrix(e))

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(int(e[s-1][t-1]-1))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n+1) for _ in range(n+1)]
e=[[sys.maxsize]*(n+1) for _ in range(n+1)]
for i in range(n+1):
  d[0][i] = 0
  d[i][0] = 0
  d[i][i] = 0
  e[0][i] = 0
  e[i][0] = 0
  e[i][i] = 0

for _ in range(m):
  a,b,c = map(int, input().split())
  d[a][b]=c
  d[b][a]=c

for i in range(1,n+1):
  for j in range(1,n+1):#start
    for k in range(1,n+1):#end
      d[j][k]=min(d[j][k], d[j][i] + d[i][k])

for i in range(1,n+1):
  for j in range(1,n+1):
    if d[i][j] <= l:
      e[i][j] = 1

for i in range(1,n+1):
  for j in range(1,n+1):#start
    for k in range(1,n+1):#end
      e[j][k]=min(e[j][k], e[j][i] + e[i][k])

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s][t] == sys.maxsize:
    print(-1)
  else:
    print(e[s][t]-1)


Fixed submission:
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall

n,m,l = map(int, input().split())

d=[[sys.maxsize]*(n) for _ in range(n)]
e=[[sys.maxsize]*(n) for _ in range(n)]
for i in range(n):
  d[i][i] = 0
  e[i][i] = 0

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

d=floyd_warshall(csr_matrix(d))
for i in range(n):
  for j in range(n):
    if d[i][j] <= l:
      e[i][j] = 1

e=floyd_warshall(csr_matrix(e))

q=int(input())
for _ in range(q):
  s,t = map(int, input().split())
  if e[s-1][t-1] == sys.maxsize:
    print(-1)
  else:
    print(int(e[s-1][t-1]-1))