import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,M,L=map(int,readline().split())
#print("N M L:",N,M,L)

root=[[10**10 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
  A,B,C=map(int,readline().split())
  root[A][B],root[B][A]=C,C
  
Q=int(readline())
S,T=[0]*Q,[0]*Q
for i in range(Q):
  S[i],T[i]=map(int,readline().split())
#print("root:",root)
#print("S:",S)
#print("T:",T)

for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root:",root)
for i in range(1,N+1):
  for j in range(1,N+1):
    if root[i][j]<=L:
      root[i][j]=1
    else:
      root[i][j]=10**10
#print("root(1):",root)

for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      if root[i][k]!=-1 and root[k][j]!=-1:
        root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root(2):",root)

for i in range(Q):
  print(root[S[i]][T[i]]-1 if root[S[i]][T[i]]<10**10 else -1) import sys sys read=sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline=sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines=sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines N,M,L=map(int,readline().split()) N map(int,readline().split()) map int readline().split() ().split () readline split M L [10**10 for i in range(N+1)] for j in range(N+1) for j in range(N+1) j range(N+1) range N+1 N 1 for j in range(N+1) [10**10 for i in range(N+1)] root=[[10**10 for i in range(N+1)] for j in range(N+1)] root [[10**10 for i in range(N+1)] for j in range(N+1)] for i in range(M):
  A,B,C=map(int,readline().split())
  root[A][B],root[B][A]=C,C
   i range(M) range M A,B,C=map(int,readline().split()) A map(int,readline().split()) map int readline().split() ().split () readline split B C root[A][B],root[B][A]=C,C root[A][B] [A] root A B C root[B][A] [B] root B A C Q=int(readline()) Q int(readline()) int readline() readline S,T=[0]*Q,[0]*Q S [0]*Q [0] 0 Q T [0]*Q [0] 0 Q for i in range(Q):
  S[i],T[i]=map(int,readline().split())
#print("root:",root)
#print("S:",S)
#print("T:",T) i range(Q) range Q S[i],T[i]=map(int,readline().split()) S[i] S i map(int,readline().split()) map int readline().split() ().split () readline split T[i] T i for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root:",root) k range(1,N+1) range 1 N+1 N 1 for i in range(1,N+1):
    for j in range(1,N+1):
      root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root:",root) i range(1,N+1) range 1 N+1 N 1 for j in range(1,N+1):
      root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root:",root) j range(1,N+1) range 1 N+1 N 1 root[i][j]=min(root[i][j],root[i][k]+root[k][j]) root[i][j] [i] root i j min(root[i][j],root[i][k]+root[k][j]) min root[i][j] [i] root i j root[i][k]+root[k][j] root[i][k] [i] root i k root[k][j] [k] root k j for i in range(1,N+1):
  for j in range(1,N+1):
    if root[i][j]<=L:
      root[i][j]=1
    else:
      root[i][j]=10**10
#print("root(1):",root) i range(1,N+1) range 1 N+1 N 1 for j in range(1,N+1):
    if root[i][j]<=L:
      root[i][j]=1
    else:
      root[i][j]=10**10
#print("root(1):",root) j range(1,N+1) range 1 N+1 N 1 if root[i][j]<=L:
      root[i][j]=1
    else:
      root[i][j]=10**10
#print("root(1):",root) root[i][j]<=L root[i][j] [i] root i j L root[i][j]=1 root[i][j] [i] root i j 1 root[i][j]=10**10 root[i][j] [i] root i j 10**10 10 10 for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      if root[i][k]!=-1 and root[k][j]!=-1:
        root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root(2):",root) k range(1,N+1) range 1 N+1 N 1 for i in range(1,N+1):
    for j in range(1,N+1):
      if root[i][k]!=-1 and root[k][j]!=-1:
        root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root(2):",root) i range(1,N+1) range 1 N+1 N 1 for j in range(1,N+1):
      if root[i][k]!=-1 and root[k][j]!=-1:
        root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root(2):",root) j range(1,N+1) range 1 N+1 N 1 if root[i][k]!=-1 and root[k][j]!=-1:
        root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root(2):",root) root[i][k]!=-1 and root[k][j]!=-1 root[i][k]!=-1 root[i][k] [i] root i k -1 root[k][j]!=-1 root[k][j] [k] root k j -1 root[i][j]=min(root[i][j],root[i][k]+root[k][j]) root[i][j] [i] root i j min(root[i][j],root[i][k]+root[k][j]) min root[i][j] [i] root i j root[i][k]+root[k][j] root[i][k] [i] root i k root[k][j] [k] root k j for i in range(Q):
  print(root[S[i]][T[i]]-1 if root[S[i]][T[i]]<10**10 else -1) i range(Q) range Q print(root[S[i]][T[i]]-1 if root[S[i]][T[i]]<10**10 else -1) print root[S[i]][T[i]]-1 if root[S[i]][T[i]]<10**10 else -1 root[S[i]][T[i]]<10**10 root[S[i]][T[i]] [S[i]] root S[i] S i T[i] T i 10**10 10 10 root[S[i]][T[i]]-1 root[S[i]][T[i]] [S[i]] root S[i] S i T[i] T i 1 -1 read=sys.stdin.buffer.read sys.stdin.buffer.read read C=map(int,readline().split()) map(int,readline().split()) C N,M,L=map(int,readline().split()) map(int,readline().split()) N Q=int(readline()) int(readline()) Q S,T=[0]*Q,[0]*Q [0]*Q S T=[0]*Q,[0]*Q [0]*Q T root=[[10**10 for i in range(N+1)] for j in range(N+1)] [[10**10 for i in range(N+1)] for j in range(N+1)] root B,C=map(int,readline().split()) map(int,readline().split()) B readline=sys.stdin.buffer.readline sys.stdin.buffer.readline readline M,L=map(int,readline().split()) map(int,readline().split()) M A,B,C=map(int,readline().split()) map(int,readline().split()) A readlines=sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines L=map(int,readline().split()) map(int,readline().split()) L
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

N,M,L=map(int,readline().split())
#print("N M L:",N,M,L)

root=[[10**10 for i in range(N+1)] for j in range(N+1)]
for i in range(M):
  A,B,C=map(int,readline().split())
  root[A][B],root[B][A]=C,C
  
Q=int(readline())
S,T=[0]*Q,[0]*Q
for i in range(Q):
  S[i],T[i]=map(int,readline().split())
#print("root:",root)
#print("S:",S)
#print("T:",T)

for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root:",root)
for i in range(1,N+1):
  for j in range(1,N+1):
    if root[i][j]<=L:
      root[i][j]=1
    else:
      root[i][j]=10**10
#print("root(1):",root)

for k in range(1,N+1):
  for i in range(1,N+1):
    for j in range(1,N+1):
      if root[i][k]!=-1 and root[k][j]!=-1:
        root[i][j]=min(root[i][j],root[i][k]+root[k][j])
#print("root(2):",root)

for i in range(Q):
  print(root[S[i]][T[i]]-1 if root[S[i]][T[i]]<10**10 else -1)