def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e

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

edge=[n*[10**18]for _ in range(n)]
for i in range(n):
  edge[i][i]=0
for i in range(m):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  edge[a][b]=edge[b][a]=c
edge=warshall_floyd(edge)

edge2=[n*[10**18]for _ in range(n)]
for i in range(n):
  edge2[i][i]=0
  for j in range(n):
    if edge[i][j]<=l:
      edge2[i][j]=1

edge2=warshall_floyd(edge2)
q=int(input())
for i in range(q):
  s,t=map(int,input().split())
  s-=1
  t-=1
  ans=edge2[s][t]
  if ans==10**18:
    print(-1)
  else:
    print(ans-1) def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e warshall_floyd e=edge e edge for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
   k range(len(e)) range len(e) len e for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
   i range(len(e)) range len(e) len e for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
   j range(len(e)) range len(e) len e e[i][j]=min(e[i][j],e[i][k]+e[k][j]) e[i][j] [i] e i j min(e[i][j],e[i][k]+e[k][j]) min e[i][j] [i] e i j e[i][k]+e[k][j] e[i][k] [i] e i k e[k][j] [k] e k j return e e edge edge n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l n*[10**18]for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) n*[10**18] n [10**18] 10**18 10 18 edge=[n*[10**18]for _ in range(n)] edge [n*[10**18]for _ in range(n)] for i in range(n):
  edge[i][i]=0 i range(n) range n edge[i][i]=0 edge[i][i] [i] edge i i 0 for i in range(m):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  edge[a][b]=edge[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 edge[a][b]=edge[b][a]=c edge[a][b] [a] edge a b c =edge[b][a]=c edge[b][a] [b] edge b a c edge=warshall_floyd(edge) edge warshall_floyd(edge) warshall_floyd edge n*[10**18]for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) n*[10**18] n [10**18] 10**18 10 18 edge2=[n*[10**18]for _ in range(n)] edge2 [n*[10**18]for _ in range(n)] for i in range(n):
  edge2[i][i]=0
  for j in range(n):
    if edge[i][j]<=l:
      edge2[i][j]=1 i range(n) range n edge2[i][i]=0 edge2[i][i] [i] edge2 i i 0 for j in range(n):
    if edge[i][j]<=l:
      edge2[i][j]=1 j range(n) range n if edge[i][j]<=l:
      edge2[i][j]=1 edge[i][j]<=l edge[i][j] [i] edge i j l edge2[i][j]=1 edge2[i][j] [i] edge2 i j 1 edge2=warshall_floyd(edge2) edge2 warshall_floyd(edge2) warshall_floyd edge2 q=int(input()) q int(input()) int input() input for i in range(q):
  s,t=map(int,input().split())
  s-=1
  t-=1
  ans=edge2[s][t]
  if ans==10**18:
    print(-1)
  else:
    print(ans-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 ans=edge2[s][t] ans edge2[s][t] [s] edge2 s t if ans==10**18:
    print(-1)
  else:
    print(ans-1) ans==10**18 ans 10**18 10 18 print(-1) print -1 print(ans-1) print ans-1 ans 1 def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e warshall_floyd t=map(int,input().split()) map(int,input().split()) t edge=warshall_floyd(edge) warshall_floyd(edge) edge b,c=map(int,input().split()) map(int,input().split()) b ans=edge2[s][t] edge2[s][t] ans c=map(int,input().split()) map(int,input().split()) c t-=1 1 t q=int(input()) int(input()) q s,t=map(int,input().split()) map(int,input().split()) s n,m,l=map(int,input().split()) map(int,input().split()) n l=map(int,input().split()) map(int,input().split()) l edge=[n*[10**18]for _ in range(n)] [n*[10**18]for _ in range(n)] edge s-=1 1 s a-=1 1 a edge2=[n*[10**18]for _ in range(n)] [n*[10**18]for _ in range(n)] edge2 m,l=map(int,input().split()) map(int,input().split()) m a,b,c=map(int,input().split()) map(int,input().split()) a b-=1 1 b edge2=warshall_floyd(edge2) warshall_floyd(edge2) edge2
def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):
        e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e

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

edge=[n*[10**18]for _ in range(n)]
for i in range(n):
  edge[i][i]=0
for i in range(m):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  edge[a][b]=edge[b][a]=c
edge=warshall_floyd(edge)

edge2=[n*[10**18]for _ in range(n)]
for i in range(n):
  edge2[i][i]=0
  for j in range(n):
    if edge[i][j]<=l:
      edge2[i][j]=1

edge2=warshall_floyd(edge2)
q=int(input())
for i in range(q):
  s,t=map(int,input().split())
  s-=1
  t-=1
  ans=edge2[s][t]
  if ans==10**18:
    print(-1)
  else:
    print(ans-1)
