import sys
input=sys.stdin.readline
N,M,L=map(int,input().split())

def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(size_v):
    for i in range(size_v):
      for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

# vlistに点のリスト、dist[vi][vj]に辺(vi,vj)のコストを入れて呼び出す
size_v=N+1
dist=[[float("inf")]*size_v for i in range(size_v)]
for _ in range(M):
  A,B,C=map(int,input().split())
  dist[A][B]=C
  dist[B][A]=C
for i in range(size_v):
  dist[i][i]=0 #自身のところに行くコストは0

dist=warshall_floyd(dist)
#print(dist)

dist2=[[float("inf")]*size_v for i in range(size_v)]
for i in range(size_v):
  for j in range(size_v):
    if dist[i][j]<=L:
      dist2[i][j]=1
for i in range(size_v):
  dist2[i][i]=0 #自身のところに行くコストは0

dist2=warshall_floyd(dist2)
#print(dist2)

Q=int(input())
for _ in range(Q):
  s,t=map(int,input().split())
  answer=dist2[s][t]-1
  if answer==float("inf"):
    print(-1)
  else:
    print(answer) 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 def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(size_v):
    for i in range(size_v):
      for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

# vlistに点のリスト、dist[vi][vj]に辺(vi,vj)のコストを入れて呼び出す warshall_floyd for k in range(size_v):
    for i in range(size_v):
      for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
   k range(size_v) range size_v for i in range(size_v):
      for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
   i range(size_v) range size_v for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
   j range(size_v) range size_v d[i][j]=min(d[i][j],d[i][k]+d[k][j]) d[i][j] [i] d i j min(d[i][j],d[i][k]+d[k][j]) min d[i][j] [i] d i j d[i][k]+d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d d d size_v=N+1 size_v N+1 N 1 [float("inf")]*size_v for i in range(size_v) for i in range(size_v) i range(size_v) range size_v for i in range(size_v) [float("inf")]*size_v [float("inf")] float("inf") float "inf" size_v dist=[[float("inf")]*size_v for i in range(size_v)] dist [[float("inf")]*size_v for i in range(size_v)] for _ in range(M):
  A,B,C=map(int,input().split())
  dist[A][B]=C
  dist[B][A]=C _ 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 dist[A][B]=C dist[A][B] [A] dist A B C dist[B][A]=C dist[B][A] [B] dist B A C for i in range(size_v):
  dist[i][i]=0 #自身のところに行くコストは0 i range(size_v) range size_v dist[i][i]=0 dist[i][i] [i] dist i i 0 dist=warshall_floyd(dist) dist warshall_floyd(dist) warshall_floyd dist [float("inf")]*size_v for i in range(size_v) for i in range(size_v) i range(size_v) range size_v for i in range(size_v) [float("inf")]*size_v [float("inf")] float("inf") float "inf" size_v dist2=[[float("inf")]*size_v for i in range(size_v)] dist2 [[float("inf")]*size_v for i in range(size_v)] for i in range(size_v):
  for j in range(size_v):
    if dist[i][j]<=L:
      dist2[i][j]=1 i range(size_v) range size_v for j in range(size_v):
    if dist[i][j]<=L:
      dist2[i][j]=1 j range(size_v) range size_v if dist[i][j]<=L:
      dist2[i][j]=1 dist[i][j]<=L dist[i][j] [i] dist i j L dist2[i][j]=1 dist2[i][j] [i] dist2 i j 1 for i in range(size_v):
  dist2[i][i]=0 #自身のところに行くコストは0 i range(size_v) range size_v dist2[i][i]=0 dist2[i][i] [i] dist2 i i 0 dist2=warshall_floyd(dist2) dist2 warshall_floyd(dist2) warshall_floyd dist2 Q=int(input()) Q int(input()) int input() input for _ in range(Q):
  s,t=map(int,input().split())
  answer=dist2[s][t]-1
  if answer==float("inf"):
    print(-1)
  else:
    print(answer) _ range(Q) range Q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t answer=dist2[s][t]-1 answer dist2[s][t]-1 dist2[s][t] [s] dist2 s t 1 if answer==float("inf"):
    print(-1)
  else:
    print(answer) answer==float("inf") answer float("inf") float "inf" print(-1) print -1 print(answer) print answer t=map(int,input().split()) map(int,input().split()) t N,M,L=map(int,input().split()) map(int,input().split()) N dist=[[float("inf")]*size_v for i in range(size_v)] [[float("inf")]*size_v for i in range(size_v)] dist input=sys.stdin.readline sys.stdin.readline input s,t=map(int,input().split()) map(int,input().split()) s Q=int(input()) int(input()) Q C=map(int,input().split()) map(int,input().split()) C B,C=map(int,input().split()) map(int,input().split()) B def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(size_v):
    for i in range(size_v):
      for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

# vlistに点のリスト、dist[vi][vj]に辺(vi,vj)のコストを入れて呼び出す def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(size_v):
    for i in range(size_v):
      for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

# vlistに点のリスト、dist[vi][vj]に辺(vi,vj)のコストを入れて呼び出す warshall_floyd answer=dist2[s][t]-1 dist2[s][t]-1 answer dist2=warshall_floyd(dist2) warshall_floyd(dist2) dist2 M,L=map(int,input().split()) map(int,input().split()) M L=map(int,input().split()) map(int,input().split()) L dist2=[[float("inf")]*size_v for i in range(size_v)] [[float("inf")]*size_v for i in range(size_v)] dist2 dist=warshall_floyd(dist) warshall_floyd(dist) dist A,B,C=map(int,input().split()) map(int,input().split()) A size_v=N+1 N+1 size_v
import sys
input=sys.stdin.readline
N,M,L=map(int,input().split())

def warshall_floyd(d):
  #d[i][j]: iからjへの最短距離
  for k in range(size_v):
    for i in range(size_v):
      for j in range(size_v):
        d[i][j]=min(d[i][j],d[i][k]+d[k][j])
  return d

# vlistに点のリスト、dist[vi][vj]に辺(vi,vj)のコストを入れて呼び出す
size_v=N+1
dist=[[float("inf")]*size_v for i in range(size_v)]
for _ in range(M):
  A,B,C=map(int,input().split())
  dist[A][B]=C
  dist[B][A]=C
for i in range(size_v):
  dist[i][i]=0 #自身のところに行くコストは0

dist=warshall_floyd(dist)
#print(dist)

dist2=[[float("inf")]*size_v for i in range(size_v)]
for i in range(size_v):
  for j in range(size_v):
    if dist[i][j]<=L:
      dist2[i][j]=1
for i in range(size_v):
  dist2[i][i]=0 #自身のところに行くコストは0

dist2=warshall_floyd(dist2)
#print(dist2)

Q=int(input())
for _ in range(Q):
  s,t=map(int,input().split())
  answer=dist2[s][t]-1
  if answer==float("inf"):
    print(-1)
  else:
    print(answer)