import sys
input=sys.stdin.readline
n,m,l=map(int,input().split())
INF=10**10
graph=[[INF for i in range(n)] for j in range(n)]
fuel=[[INF for i in range(n)] for j in range(n)]
#for i in range(n):
#    graph[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    if c>l:continue
    graph[a][b],graph[b][a]=c,c
for i in range(n):
  for j in range(n):
    for k in range(n):
      graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k])
for i in range(n):
    for j in range(n):
        if graph[i][j]<=l:
            fuel[i][j]=1
for i in range(n):
  for j in range(n):
    for k in range(n):
      fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k])
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    s-=1;t-=1
    if fuel[s][t]==INF:print(-1)
    else:print(fuel[s][t]-1) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l INF=10**10 INF 10**10 10 10 [INF for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [INF for i in range(n)] graph=[[INF for i in range(n)] for j in range(n)] graph [[INF for i in range(n)] for j in range(n)] [INF for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [INF for i in range(n)] fuel=[[INF for i in range(n)] for j in range(n)] fuel [[INF for i in range(n)] for j in range(n)] for i in range(m):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    if c>l:continue
    graph[a][b],graph[b][a]=c,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 if c>l:continue
     c>l c l graph[a][b],graph[b][a]=c,c graph[a][b] [a] graph a b c graph[b][a] [b] graph b a c for i in range(n):
  for j in range(n):
    for k in range(n):
      graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k]) i range(n) range n for j in range(n):
    for k in range(n):
      graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k]) j range(n) range n for k in range(n):
      graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k]) k range(n) range n graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k]) graph[j][k] [j] graph j k min(graph[j][k],graph[j][i]+graph[i][k]) min graph[j][k] [j] graph j k graph[j][i]+graph[i][k] graph[j][i] [j] graph j i graph[i][k] [i] graph i k for i in range(n):
    for j in range(n):
        if graph[i][j]<=l:
            fuel[i][j]=1 i range(n) range n for j in range(n):
        if graph[i][j]<=l:
            fuel[i][j]=1 j range(n) range n if graph[i][j]<=l:
            fuel[i][j]=1 graph[i][j]<=l graph[i][j] [i] graph i j l fuel[i][j]=1 fuel[i][j] [i] fuel i j 1 for i in range(n):
  for j in range(n):
    for k in range(n):
      fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k]) i range(n) range n for j in range(n):
    for k in range(n):
      fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k]) j range(n) range n for k in range(n):
      fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k]) k range(n) range n fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k]) fuel[j][k] [j] fuel j k min(fuel[j][k],fuel[j][i]+fuel[i][k]) min fuel[j][k] [j] fuel j k fuel[j][i]+fuel[i][k] fuel[j][i] [j] fuel j i fuel[i][k] [i] fuel i k q=int(input()) q int(input()) int input() input for i in range(q):
    s,t=map(int,input().split())
    s-=1;t-=1
    if fuel[s][t]==INF:print(-1)
    else:print(fuel[s][t]-1) i 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 if fuel[s][t]==INF:print(-1)
    else:print(fuel[s][t]-1) fuel[s][t]==INF fuel[s][t] [s] fuel s t INF n,m,l=map(int,input().split()) map(int,input().split()) n fuel=[[INF for i in range(n)] for j in range(n)] [[INF for i in range(n)] for j in range(n)] fuel b-=1 1 b INF=10**10 10**10 INF t-=1 1 t b,c=map(int,input().split()) map(int,input().split()) b a,b,c=map(int,input().split()) map(int,input().split()) a graph=[[INF for i in range(n)] for j in range(n)] [[INF for i in range(n)] for j in range(n)] graph a-=1 1 a input=sys.stdin.readline sys.stdin.readline input m,l=map(int,input().split()) map(int,input().split()) m l=map(int,input().split()) map(int,input().split()) l s,t=map(int,input().split()) map(int,input().split()) s t=map(int,input().split()) map(int,input().split()) t q=int(input()) int(input()) q c=map(int,input().split()) map(int,input().split()) c s-=1 1 s
import sys
input=sys.stdin.readline
n,m,l=map(int,input().split())
INF=10**10
graph=[[INF for i in range(n)] for j in range(n)]
fuel=[[INF for i in range(n)] for j in range(n)]
#for i in range(n):
#    graph[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    if c>l:continue
    graph[a][b],graph[b][a]=c,c
for i in range(n):
  for j in range(n):
    for k in range(n):
      graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k])
for i in range(n):
    for j in range(n):
        if graph[i][j]<=l:
            fuel[i][j]=1
for i in range(n):
  for j in range(n):
    for k in range(n):
      fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k])
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    s-=1;t-=1
    if fuel[s][t]==INF:print(-1)
    else:print(fuel[s][t]-1)