n,m,l = map(int,input().split())
abe = [list(map(int,input().split())) for i in range(m)]
dist = [[10**18 for i in range(n)] for i in range(n)]
for a,b,e in abe:
  dist[a-1][b-1] = e
  dist[b-1][a-1] = e
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
for i in range(n):
  for j in range(n):
    if dist[i][j] <= l:
      dist[i][j] = 1
    else:
      dist[i][j] = 10**18
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
q = int(input())
for i in range(q):
  s,t = map(int,input().split())
  x = dist[s-1][t-1]-1
  if x == 10**18-1:
    print(-1)
  else:
    print(x) n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l list(map(int,input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split abe = [list(map(int,input().split())) for i in range(m)] abe [list(map(int,input().split())) for i in range(m)] [10**18 for i in range(n)] for i in range(n) for i in range(n) i range(n) range n for i in range(n) [10**18 for i in range(n)] dist = [[10**18 for i in range(n)] for i in range(n)] dist [[10**18 for i in range(n)] for i in range(n)] for a,b,e in abe:
  dist[a-1][b-1] = e
  dist[b-1][a-1] = e a b e abe dist[a-1][b-1] = e dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 e dist[b-1][a-1] = e dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 e for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) k range(n) range n for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) i range(n) range n for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) j range(n) range n dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j],dist[i][k]+dist[k][j]) min dist[i][j] [i] dist i j dist[i][k]+dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j for i in range(n):
  for j in range(n):
    if dist[i][j] <= l:
      dist[i][j] = 1
    else:
      dist[i][j] = 10**18 i range(n) range n for j in range(n):
    if dist[i][j] <= l:
      dist[i][j] = 1
    else:
      dist[i][j] = 10**18 j range(n) range n if dist[i][j] <= l:
      dist[i][j] = 1
    else:
      dist[i][j] = 10**18 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] = 10**18 dist[i][j] [i] dist i j 10**18 10 18 for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) k range(n) range n for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) i range(n) range n for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) j range(n) range n dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j],dist[i][k]+dist[k][j]) min dist[i][j] [i] dist i j dist[i][k]+dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j q = int(input()) q int(input()) int input() input for i in range(q):
  s,t = map(int,input().split())
  x = dist[s-1][t-1]-1
  if x == 10**18-1:
    print(-1)
  else:
    print(x) i range(q) range q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t x = dist[s-1][t-1]-1 x dist[s-1][t-1]-1 dist[s-1][t-1] [s-1] dist s-1 s 1 t-1 t 1 1 if x == 10**18-1:
    print(-1)
  else:
    print(x) x == 10**18-1 x 10**18-1 10**18 10 18 1 print(-1) print -1 print(x) print x q = int(input()) int(input()) q m,l = map(int,input().split()) map(int,input().split()) m t = map(int,input().split()) map(int,input().split()) t dist = [[10**18 for i in range(n)] for i in range(n)] [[10**18 for i in range(n)] for i in range(n)] dist x = dist[s-1][t-1]-1 dist[s-1][t-1]-1 x l = map(int,input().split()) map(int,input().split()) l abe = [list(map(int,input().split())) for i in range(m)] [list(map(int,input().split())) for i in range(m)] abe n,m,l = map(int,input().split()) map(int,input().split()) n s,t = map(int,input().split()) map(int,input().split()) s
n,m,l = map(int,input().split())
abe = [list(map(int,input().split())) for i in range(m)]
dist = [[10**18 for i in range(n)] for i in range(n)]
for a,b,e in abe:
  dist[a-1][b-1] = e
  dist[b-1][a-1] = e
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
for i in range(n):
  for j in range(n):
    if dist[i][j] <= l:
      dist[i][j] = 1
    else:
      dist[i][j] = 10**18
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
q = int(input())
for i in range(q):
  s,t = map(int,input().split())
  x = dist[s-1][t-1]-1
  if x == 10**18-1:
    print(-1)
  else:
    print(x)