n,m,l = map(int, input().split())
INF = 1001001001
dist = [[INF for i in range(n)] for i in range(n)]
#make graph
for i in range(n):
  dist[i][i] = 0
for i in range(m):
  a, b, c = map(int, input().split())
  dist[a-1][b-1] = dist[b-1][a-1] = c
#warshall-froyd
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])
dist2 =  [[INF for i in range(n)] for i in range(n)]
for i in range(n):
  for j in range(n):
    if dist[i][j] <=l:
      dist2[i][j] = 1
#warshall-froyd
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j])
q = int(input())
for i in range(q):
  s,t = map(int, input().split())
  if dist2[s-1][t-1] == INF:
    print(-1)
  else:
    print(dist2[s-1][t-1]-1) n,m,l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l INF = 1001001001 INF 1001001001 [INF 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) [INF for i in range(n)] dist = [[INF for i in range(n)] for i in range(n)] dist [[INF for i in range(n)] for i in range(n)] for i in range(n):
  dist[i][i] = 0 i range(n) range n dist[i][i] = 0 dist[i][i] [i] dist i i 0 for i in range(m):
  a, b, c = map(int, input().split())
  dist[a-1][b-1] = dist[b-1][a-1] = c
#warshall-froyd 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 dist[a-1][b-1] = dist[b-1][a-1] = c dist[a-1][b-1] [a-1] dist a-1 a 1 b-1 b 1 c = dist[b-1][a-1] = c dist[b-1][a-1] [b-1] dist b-1 b 1 a-1 a 1 c 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 [INF 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) [INF for i in range(n)] dist2 =  [[INF for i in range(n)] for i in range(n)] dist2 [[INF for i in range(n)] for i in range(n)] for i in range(n):
  for j in range(n):
    if dist[i][j] <=l:
      dist2[i][j] = 1
#warshall-froyd i range(n) range n for j in range(n):
    if dist[i][j] <=l:
      dist2[i][j] = 1
#warshall-froyd j range(n) range n if dist[i][j] <=l:
      dist2[i][j] = 1
#warshall-froyd 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 k in range(n):
  for i in range(n):
    for j in range(n):
      dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j]) k range(n) range n for i in range(n):
    for j in range(n):
      dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j]) i range(n) range n for j in range(n):
      dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j]) j range(n) range n dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j]) dist2[i][j] [i] dist2 i j min(dist2[i][j], dist2[i][k]+dist2[k][j]) min dist2[i][j] [i] dist2 i j dist2[i][k]+dist2[k][j] dist2[i][k] [i] dist2 i k dist2[k][j] [k] dist2 k j q = int(input()) q int(input()) int input() input for i in range(q):
  s,t = map(int, input().split())
  if dist2[s-1][t-1] == INF:
    print(-1)
  else:
    print(dist2[s-1][t-1]-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 if dist2[s-1][t-1] == INF:
    print(-1)
  else:
    print(dist2[s-1][t-1]-1) dist2[s-1][t-1] == INF dist2[s-1][t-1] [s-1] dist2 s-1 s 1 t-1 t 1 INF print(-1) print -1 print(dist2[s-1][t-1]-1) print dist2[s-1][t-1]-1 dist2[s-1][t-1] [s-1] dist2 s-1 s 1 t-1 t 1 1 n,m,l = map(int, input().split()) map(int, input().split()) n q = int(input()) int(input()) q dist = [[INF for i in range(n)] for i in range(n)] [[INF for i in range(n)] for i in range(n)] dist b, c = map(int, input().split()) map(int, input().split()) b dist2 =  [[INF for i in range(n)] for i in range(n)] [[INF for i in range(n)] for i in range(n)] dist2 l = map(int, input().split()) map(int, input().split()) l a, b, c = map(int, input().split()) map(int, input().split()) a INF = 1001001001 1001001001 INF c = map(int, input().split()) map(int, input().split()) c m,l = map(int, input().split()) map(int, input().split()) m s,t = map(int, input().split()) map(int, input().split()) s t = map(int, input().split()) map(int, input().split()) t
n,m,l = map(int, input().split())
INF = 1001001001
dist = [[INF for i in range(n)] for i in range(n)]
#make graph
for i in range(n):
  dist[i][i] = 0
for i in range(m):
  a, b, c = map(int, input().split())
  dist[a-1][b-1] = dist[b-1][a-1] = c
#warshall-froyd
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])
dist2 =  [[INF for i in range(n)] for i in range(n)]
for i in range(n):
  for j in range(n):
    if dist[i][j] <=l:
      dist2[i][j] = 1
#warshall-froyd
for k in range(n):
  for i in range(n):
    for j in range(n):
      dist2[i][j] = min(dist2[i][j], dist2[i][k]+dist2[k][j])
q = int(input())
for i in range(q):
  s,t = map(int, input().split())
  if dist2[s-1][t-1] == INF:
    print(-1)
  else:
    print(dist2[s-1][t-1]-1)