import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int,input().split())
INF = 1 << 31
dist=np.array([[INF for _ in range(N)] for _ in range(N)])

for i in range(N):
  dist[i][i]=0
  
for i in range(M):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  dist[a][b]=c
  dist[b][a]=c

dist = floyd_warshall(dist)

for i in range(N):
  for j in range(N):
    if dist[i][j]<=L:
      dist[i][j]=1
    else:
      dist[i][j]=INF

dist = floyd_warshall(dist)
dist[dist==INF]=0
#dist=dist.astype(int)
#print(dist)

Q=int(input())
ans=[0]*Q
for q in range(Q):
  s,t=map(int,input().split())
  s-=1
  t-=1
  ans[q]=int(dist[s][t]-1)

print(*ans,sep='\n')
 import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall N,M,L=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L INF = 1 << 31 INF 1 << 31 1 31 [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] dist=np.array([[INF for _ in range(N)] for _ in range(N)]) dist np.array([[INF for _ in range(N)] for _ in range(N)]) np.array np array [[INF for _ in range(N)] for _ in range(N)] for i in range(N):
  dist[i][i]=0
   i range(N) range N dist[i][i]=0 dist[i][i] [i] dist i i 0 for i in range(M):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  dist[a][b]=c
  dist[b][a]=c i range(M) range M a,b,c=map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b c a-=1 a 1 b-=1 b 1 dist[a][b]=c dist[a][b] [a] dist a b c dist[b][a]=c dist[b][a] [b] dist b a c dist = floyd_warshall(dist) dist floyd_warshall(dist) floyd_warshall dist for i in range(N):
  for j in range(N):
    if dist[i][j]<=L:
      dist[i][j]=1
    else:
      dist[i][j]=INF i range(N) range N for j in range(N):
    if dist[i][j]<=L:
      dist[i][j]=1
    else:
      dist[i][j]=INF j range(N) range N if dist[i][j]<=L:
      dist[i][j]=1
    else:
      dist[i][j]=INF dist[i][j]<=L dist[i][j] [i] dist i j L dist[i][j]=1 dist[i][j] [i] dist i j 1 dist[i][j]=INF dist[i][j] [i] dist i j INF dist = floyd_warshall(dist) dist floyd_warshall(dist) floyd_warshall dist dist[dist==INF]=0 dist[dist==INF] dist dist==INF dist INF 0 Q=int(input()) Q int(input()) int input() input ans=[0]*Q ans [0]*Q [0] 0 Q for q in range(Q):
  s,t=map(int,input().split())
  s-=1
  t-=1
  ans[q]=int(dist[s][t]-1) q range(Q) range Q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t s-=1 s 1 t-=1 t 1 ans[q]=int(dist[s][t]-1) ans[q] ans q int(dist[s][t]-1) int dist[s][t]-1 dist[s][t] [s] dist s t 1 print(*ans,sep='\n') print *ans ans sep='\n' sep '\n' s-=1 1 s dist = floyd_warshall(dist) floyd_warshall(dist) dist t-=1 1 t dist = floyd_warshall(dist) floyd_warshall(dist) dist b-=1 1 b N,M,L=map(int,input().split()) map(int,input().split()) N b,c=map(int,input().split()) map(int,input().split()) b INF = 1 << 31 1 << 31 INF c=map(int,input().split()) map(int,input().split()) c L=map(int,input().split()) map(int,input().split()) L t=map(int,input().split()) map(int,input().split()) t a-=1 1 a Q=int(input()) int(input()) Q a,b,c=map(int,input().split()) map(int,input().split()) a ans=[0]*Q [0]*Q ans s,t=map(int,input().split()) map(int,input().split()) s dist=np.array([[INF for _ in range(N)] for _ in range(N)]) np.array([[INF for _ in range(N)] for _ in range(N)]) dist M,L=map(int,input().split()) map(int,input().split()) M
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N,M,L=map(int,input().split())
INF = 1 << 31
dist=np.array([[INF for _ in range(N)] for _ in range(N)])

for i in range(N):
  dist[i][i]=0
  
for i in range(M):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  dist[a][b]=c
  dist[b][a]=c

dist = floyd_warshall(dist)

for i in range(N):
  for j in range(N):
    if dist[i][j]<=L:
      dist[i][j]=1
    else:
      dist[i][j]=INF

dist = floyd_warshall(dist)
dist[dist==INF]=0
#dist=dist.astype(int)
#print(dist)

Q=int(input())
ans=[0]*Q
for q in range(Q):
  s,t=map(int,input().split())
  s-=1
  t-=1
  ans[q]=int(dist[s][t]-1)

print(*ans,sep='\n')

