from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline
def solve():
  inf = float("Inf")
  n,m,l = (int(i) for i in input().split())
  path = [[-1*inf]*n for _ in range(n)]
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    path[a-1][b-1] = c
    path[b-1][a-1] = c
  d = floyd_warshall(path)
  q = int(input())
  minipath = [[-1*inf]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
  d2 = floyd_warshall(minipath)

  for i in range(q):
    s,t = (int(i) for i in input().split())
    s,t = s-1,t-1
    cost = d2[s][t]
    if cost == inf:
      print(-1)
    else:
      print(int(cost)-1)

solve() from scipy.sparse.csgraph import floyd_warshall import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def solve():
  inf = float("Inf")
  n,m,l = (int(i) for i in input().split())
  path = [[-1*inf]*n for _ in range(n)]
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    path[a-1][b-1] = c
    path[b-1][a-1] = c
  d = floyd_warshall(path)
  q = int(input())
  minipath = [[-1*inf]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
  d2 = floyd_warshall(minipath)

  for i in range(q):
    s,t = (int(i) for i in input().split())
    s,t = s-1,t-1
    cost = d2[s][t]
    if cost == inf:
      print(-1)
    else:
      print(int(cost)-1) solve inf = float("Inf") inf float("Inf") float "Inf" int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n,m,l = (int(i) for i in input().split()) n (int(i) for i in input().split()) m l [-1*inf]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [-1*inf]*n [-1*inf] -1*inf -1 inf n path = [[-1*inf]*n for _ in range(n)] path [[-1*inf]*n for _ in range(n)] for i in range(m):
    a,b,c = (int(i) for i in input().split())
    path[a-1][b-1] = c
    path[b-1][a-1] = c
   i range(m) range m int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i a,b,c = (int(i) for i in input().split()) a (int(i) for i in input().split()) b c path[a-1][b-1] = c path[a-1][b-1] [a-1] path a-1 a 1 b-1 b 1 c path[b-1][a-1] = c path[b-1][a-1] [b-1] path b-1 b 1 a-1 a 1 c d = floyd_warshall(path) d floyd_warshall(path) floyd_warshall path q = int(input()) q int(input()) int input() input [-1*inf]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [-1*inf]*n [-1*inf] -1*inf -1 inf n minipath = [[-1*inf]*n for _ in range(n)] minipath [[-1*inf]*n for _ in range(n)] for i in range(n):
    for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
   i range(n) range n for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
   j range(n) range n if d[i][j] <= l:
        minipath[i][j] = 1
   d[i][j] <= l d[i][j] [i] d i j l minipath[i][j] = 1 minipath[i][j] [i] minipath i j 1 d2 = floyd_warshall(minipath) d2 floyd_warshall(minipath) floyd_warshall minipath for i in range(q):
    s,t = (int(i) for i in input().split())
    s,t = s-1,t-1
    cost = d2[s][t]
    if cost == inf:
      print(-1)
    else:
      print(int(cost)-1) i range(q) range q int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i s,t = (int(i) for i in input().split()) s (int(i) for i in input().split()) t s,t = s-1,t-1 s s-1 s 1 t t-1 t 1 cost = d2[s][t] cost d2[s][t] [s] d2 s t if cost == inf:
      print(-1)
    else:
      print(int(cost)-1) cost == inf cost inf print(-1) print -1 print(int(cost)-1) print int(cost)-1 int(cost) int cost 1 solve() solve input = sys.stdin.readline sys.stdin.readline input def solve():
  inf = float("Inf")
  n,m,l = (int(i) for i in input().split())
  path = [[-1*inf]*n for _ in range(n)]
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    path[a-1][b-1] = c
    path[b-1][a-1] = c
  d = floyd_warshall(path)
  q = int(input())
  minipath = [[-1*inf]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
  d2 = floyd_warshall(minipath)

  for i in range(q):
    s,t = (int(i) for i in input().split())
    s,t = s-1,t-1
    cost = d2[s][t]
    if cost == inf:
      print(-1)
    else:
      print(int(cost)-1) def solve():
  inf = float("Inf")
  n,m,l = (int(i) for i in input().split())
  path = [[-1*inf]*n for _ in range(n)]
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    path[a-1][b-1] = c
    path[b-1][a-1] = c
  d = floyd_warshall(path)
  q = int(input())
  minipath = [[-1*inf]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
  d2 = floyd_warshall(minipath)

  for i in range(q):
    s,t = (int(i) for i in input().split())
    s,t = s-1,t-1
    cost = d2[s][t]
    if cost == inf:
      print(-1)
    else:
      print(int(cost)-1) solve
from scipy.sparse.csgraph import floyd_warshall
import sys
input = sys.stdin.readline
def solve():
  inf = float("Inf")
  n,m,l = (int(i) for i in input().split())
  path = [[-1*inf]*n for _ in range(n)]
  for i in range(m):
    a,b,c = (int(i) for i in input().split())
    path[a-1][b-1] = c
    path[b-1][a-1] = c
  d = floyd_warshall(path)
  q = int(input())
  minipath = [[-1*inf]*n for _ in range(n)]
  for i in range(n):
    for j in range(n):
      if d[i][j] <= l:
        minipath[i][j] = 1
  d2 = floyd_warshall(minipath)

  for i in range(q):
    s,t = (int(i) for i in input().split())
    s,t = s-1,t-1
    cost = d2[s][t]
    if cost == inf:
      print(-1)
    else:
      print(int(cost)-1)

solve()