

from scipy.sparse.csgraph import floyd_warshall

n,m,l=list(map(int,input().split()))

table=[[0]*n for i in range(n)]

for i in range(m):

    a,b,c=list(map(int,input().split()))

    table[a-1][b-1]=c

    table[b-1][a-1]=c

d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)



table2=[[0]*n for i in range(n)]

for i in range(n):

  for j in range(i+1,n):

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

      table2[i][j]=1

      table2[j][i]=1

d2=floyd_warshall(csgraph=table2, directed=False, return_predecessors=False)

q=int(eval(input()))

for _ in range(q):

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

  if d2[s-1][t-1]==float("inf"):

    print((-1))

  else:

    print((int(d2[s-1][t-1])-1))
import sys

input=sys.stdin.readline

from scipy.sparse.csgraph import floyd_warshall

n,m,l=list(map(int,input().split()))

table=[[0]*n for i in range(n)]

for i in range(m):

    a,b,c=list(map(int,input().split()))

    table[a-1][b-1]=c

    table[b-1][a-1]=c

d=floyd_warshall(csgraph=table, directed=False, return_predecessors=False)



table2=[[0]*n for i in range(n)]

for i in range(n):

  for j in range(i+1,n):

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

      table2[i][j]=1

      table2[j][i]=1

d2=floyd_warshall(csgraph=table2, directed=False, return_predecessors=False)

q=int(eval(input()))

for _ in range(q):

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

  if d2[s-1][t-1]==float("inf"):

    print((-1))

  else:

    print((int(d2[s-1][t-1])-1))
from scipy.sparse.csgraph import floyd_warshall

n, m, l = list(map(int, input().split()))
table = [[0] * n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    table[a - 1][b - 1] = c
    table[b - 1][a - 1] = c
d = floyd_warshall(csgraph=table, directed=False, return_predecessors=False)
table2 = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        if d[i][j] <= l:
            table2[i][j] = 1
            table2[j][i] = 1
d2 = floyd_warshall(csgraph=table2, directed=False, return_predecessors=False)
q = int(eval(input()))
for _ in range(q):
    s, t = list(map(int, input().split()))
    if d2[s - 1][t - 1] == float("inf"):
        print((-1))
    else:
        print((int(d2[s - 1][t - 1]) - 1))

import sys

input = sys.stdin.readline
from scipy.sparse.csgraph import floyd_warshall

n, m, l = list(map(int, input().split()))
table = [[0] * n for i in range(n)]
for i in range(m):
    a, b, c = list(map(int, input().split()))
    table[a - 1][b - 1] = c
    table[b - 1][a - 1] = c
d = floyd_warshall(csgraph=table, directed=False, return_predecessors=False)
table2 = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        if d[i][j] <= l:
            table2[i][j] = 1
            table2[j][i] = 1
d2 = floyd_warshall(csgraph=table2, directed=False, return_predecessors=False)
q = int(eval(input()))
for _ in range(q):
    s, t = list(map(int, input().split()))
    if d2[s - 1][t - 1] == float("inf"):
        print((-1))
    else:
        print((int(d2[s - 1][t - 1]) - 1))

+import sys + +input = sys.stdin.readline