import sys
input = sys.stdin.readline
 
n, m, l = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
 
st = [list(map(int, input().split())) for _ in range(q)]
 
graph = [[float('inf') for _ in range(n)] for _ in range(n)]
 
 
for a, b, c in abc:
    graph[a-1][b-1] = c 
    graph[b-1][a-1] = c
for i in range(n):
    graph[i][i] = 0
 
# print(graph)
 
def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d
 
graph = warshall_floyd(graph)
 
for i in range(n):
    for j in range(n):
        if 0 < graph[i][j] <= l:
            graph[i][j] = 1
        if graph[i][j] > l:
            graph[i][j] = float('inf')
 
graph = warshall_floyd(graph)
 
for s, t in st:
    print(graph[s-1][t-1]-1 if graph[s-1][t-1] != float('inf') else -1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split abc = [list(map(int, input().split())) for _ in range(m)] abc [list(map(int, input().split())) for _ in range(m)] q = int(input()) q int(input()) int input() input list(map(int, input().split())) for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split st = [list(map(int, input().split())) for _ in range(q)] st [list(map(int, input().split())) for _ in range(q)] [float('inf') for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [float('inf') for _ in range(n)] graph = [[float('inf') for _ in range(n)] for _ in range(n)] graph [[float('inf') for _ in range(n)] for _ in range(n)] for a, b, c in abc:
    graph[a-1][b-1] = c 
    graph[b-1][a-1] = c a b c abc graph[a-1][b-1] = c graph[a-1][b-1] [a-1] graph a-1 a 1 b-1 b 1 c graph[b-1][a-1] = c graph[b-1][a-1] [b-1] graph b-1 b 1 a-1 a 1 c for i in range(n):
    graph[i][i] = 0
 
# print(graph)
  i range(n) range n graph[i][i] = 0 graph[i][i] [i] graph i i 0 def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d
  warshall_floyd for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     k range(n) range n for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     i range(n) range n for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     j range(n) range n d[i][j] = min(d[i][j], d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d d d graph = warshall_floyd(graph) graph warshall_floyd(graph) warshall_floyd graph for i in range(n):
    for j in range(n):
        if 0 < graph[i][j] <= l:
            graph[i][j] = 1
        if graph[i][j] > l:
            graph[i][j] = float('inf')
  i range(n) range n for j in range(n):
        if 0 < graph[i][j] <= l:
            graph[i][j] = 1
        if graph[i][j] > l:
            graph[i][j] = float('inf')
  j range(n) range n if 0 < graph[i][j] <= l:
            graph[i][j] = 1
         0 < graph[i][j] <= l 0 < graph[i][j] 0 graph[i][j] [i] graph i j l graph[i][j] = 1 graph[i][j] [i] graph i j 1 if graph[i][j] > l:
            graph[i][j] = float('inf')
  graph[i][j] > l graph[i][j] [i] graph i j l graph[i][j] = float('inf') graph[i][j] [i] graph i j float('inf') float 'inf' graph = warshall_floyd(graph) graph warshall_floyd(graph) warshall_floyd graph for s, t in st:
    print(graph[s-1][t-1]-1 if graph[s-1][t-1] != float('inf') else -1) s t st print(graph[s-1][t-1]-1 if graph[s-1][t-1] != float('inf') else -1) print graph[s-1][t-1]-1 if graph[s-1][t-1] != float('inf') else -1 graph[s-1][t-1] != float('inf') graph[s-1][t-1] [s-1] graph s-1 s 1 t-1 t 1 float('inf') float 'inf' graph[s-1][t-1]-1 graph[s-1][t-1] [s-1] graph s-1 s 1 t-1 t 1 1 -1 graph = warshall_floyd(graph) warshall_floyd(graph) graph input = sys.stdin.readline sys.stdin.readline input q = int(input()) int(input()) q graph = [[float('inf') for _ in range(n)] for _ in range(n)] [[float('inf') for _ in range(n)] for _ in range(n)] graph graph = warshall_floyd(graph) warshall_floyd(graph) graph l = map(int, input().split()) map(int, input().split()) l st = [list(map(int, input().split())) for _ in range(q)] [list(map(int, input().split())) for _ in range(q)] st n, m, l = map(int, input().split()) map(int, input().split()) n abc = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] abc m, l = map(int, input().split()) map(int, input().split()) m def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d
  def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d
  warshall_floyd
import sys
input = sys.stdin.readline
 
n, m, l = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
 
st = [list(map(int, input().split())) for _ in range(q)]
 
graph = [[float('inf') for _ in range(n)] for _ in range(n)]
 
 
for a, b, c in abc:
    graph[a-1][b-1] = c 
    graph[b-1][a-1] = c
for i in range(n):
    graph[i][i] = 0
 
# print(graph)
 
def warshall_floyd(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d
 
graph = warshall_floyd(graph)
 
for i in range(n):
    for j in range(n):
        if 0 < graph[i][j] <= l:
            graph[i][j] = 1
        if graph[i][j] > l:
            graph[i][j] = float('inf')
 
graph = warshall_floyd(graph)
 
for s, t in st:
    print(graph[s-1][t-1]-1 if graph[s-1][t-1] != float('inf') else -1)