import sys

input = sys.stdin.buffer.readline

N, M, L = list(map(int, input().split()))

d = [[float("inf")] * (N + 1) for _ in range(N + 1)]

for _ in range(M):

  u, v, c = list(map(int, input().split()))

  d[u][v] = c

  d[v][u] = c

Q = int(eval(input()))

for k in range(1, N + 1):

  for i in range(1, N + 1):

    for j in range(1, N + 1):

      if d[i][j] > d[i][k] + d[k][j]:

        d[i][j] = d[i][k] + d[k][j]



nd = [[float("inf")] * (N + 1) for _ in range(N + 1)]



for i in range(1, N + 1):

  for j in range(1, N + 1):

    if d[i][j] <= L:

      nd[i][j] = 1

for k in range(1, N + 1):

  for i in range(1, N + 1):

    for j in range(1, N + 1):

      if nd[i][j] > nd[i][k] + nd[k][j]:

        nd[i][j] = nd[i][k] + nd[k][j]



for _ in range(Q):

  s, t = list(map(int, input().split()))

  if nd[s][t] == float("inf"):

    print((-1))

  else:

    print((nd[s][t] - 1))
import sys

input = sys.stdin.readline

N, M, L = list(map(int, input().split()))

d = [[10 ** 16 * (i != j) for j in range(N + 1)] for i in range(N + 1)]

for _ in range(M):

  x, y, c = list(map(int, input().split()))

  d[x][y] = c

  d[y][x] = c

for k in range(N + 1):

  for i in range(N + 1):

    for j in range(N + 1): d[i][j] = min(d[i][j], d[i][k] + d[k][j])



dd = [[(d[i][j] <= L) + (d[i][j] > L) * 10 ** 16 for j in range(N + 1)] for i in range(N + 1)]

for k in range(N + 1):

  for i in range(N + 1):

    for j in range(N + 1): dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j])



for _ in range(int(eval(input()))):

  s, t = list(map(int, input().split()))

  if dd[s][t] != 10 ** 16: print((dd[s][t] - 1))

  else: print((-1))
import sys

input = sys.stdin.buffer.readline
N, M, L = list(map(int, input().split()))
d = [[float("inf")] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    u, v, c = list(map(int, input().split()))
    d[u][v] = c
    d[v][u] = c
Q = int(eval(input()))
for k in range(1, N + 1):
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]
nd = [[float("inf")] * (N + 1) for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1, N + 1):
        if d[i][j] <= L:
            nd[i][j] = 1
for k in range(1, N + 1):
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            if nd[i][j] > nd[i][k] + nd[k][j]:
                nd[i][j] = nd[i][k] + nd[k][j]
for _ in range(Q):
    s, t = list(map(int, input().split()))
    if nd[s][t] == float("inf"):
        print((-1))
    else:
        print((nd[s][t] - 1))

import sys

input = sys.stdin.readline
N, M, L = list(map(int, input().split()))
d = [[10**16 * (i != j) for j in range(N + 1)] for i in range(N + 1)]
for _ in range(M):
    x, y, c = list(map(int, input().split()))
    d[x][y] = c
    d[y][x] = c
for k in range(N + 1):
    for i in range(N + 1):
        for j in range(N + 1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])
dd = [
    [(d[i][j] <= L) + (d[i][j] > L) * 10**16 for j in range(N + 1)]
    for i in range(N + 1)
]
for k in range(N + 1):
    for i in range(N + 1):
        for j in range(N + 1):
            dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j])
for _ in range(int(eval(input()))):
    s, t = list(map(int, input().split()))
    if dd[s][t] != 10**16:
        print((dd[s][t] - 1))
    else:
        print((-1))

-input = sys.stdin.buffer.readline +input = sys.stdin.readline -d = [[float("inf")] * (N + 1) for _ in range(N + 1)] +d = [[10**16 * (i != j) for j in range(N + 1)] for i in range(N + 1)] -    u, v, c = list(map(int, input().split())) -    d[u][v] = c -    d[v][u] = c -Q = int(eval(input())) -for k in range(1, N + 1): -    for i in range(1, N + 1): -        for j in range(1, N + 1): -            if d[i][j] > d[i][k] + d[k][j]: -                d[i][j] = d[i][k] + d[k][j] -nd = [[float("inf")] * (N + 1) for _ in range(N + 1)] -for i in range(1, N + 1): -    for j in range(1, N + 1): -        if d[i][j] <= L: -            nd[i][j] = 1 -for k in range(1, N + 1): -    for i in range(1, N + 1): -        for j in range(1, N + 1): -            if nd[i][j] > nd[i][k] + nd[k][j]: -                nd[i][j] = nd[i][k] + nd[k][j] -for _ in range(Q): +    x, y, c = list(map(int, input().split())) +    d[x][y] = c +    d[y][x] = c +for k in range(N + 1): +    for i in range(N + 1): +        for j in range(N + 1): +            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) +dd = [ +    [(d[i][j] <= L) + (d[i][j] > L) * 10**16 for j in range(N + 1)] +    for i in range(N + 1) +] +for k in range(N + 1): +    for i in range(N + 1): +        for j in range(N + 1): +            dd[i][j] = min(dd[i][j], dd[i][k] + dd[k][j]) +for _ in range(int(eval(input()))): -    if nd[s][t] == float("inf"): +    if dd[s][t] != 10**16: +        print((dd[s][t] - 1)) +    else: -    else: -        print((nd[s][t] - 1))