import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import floyd_warshall
      
n,m,l = map(int,input().split())
edge = [[0]*n for _ in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    edge[a-1][b-1] = c
    edge[b-1][a-1] = c

edge = floyd_warshall(edge)
    
for i in range(n):
    for j in range(n):
        if edge[i][j]<=l:
            edge[i][j] = 1
        else:
            edge[i][j] = 0
                
edge = floyd_warshall(edge)

q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if edge[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(edge[s-1][t-1] - 1)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline from scipy.sparse.csgraph import floyd_warshall n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [0]*n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0]*n [0] 0 n edge = [[0]*n for _ in range(n)] edge [[0]*n for _ in range(n)] for i in range(m):
    a,b,c = map(int,input().split())
    edge[a-1][b-1] = c
    edge[b-1][a-1] = c 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 edge[a-1][b-1] = c edge[a-1][b-1] [a-1] edge a-1 a 1 b-1 b 1 c edge[b-1][a-1] = c edge[b-1][a-1] [b-1] edge b-1 b 1 a-1 a 1 c edge = floyd_warshall(edge) edge floyd_warshall(edge) floyd_warshall edge for i in range(n):
    for j in range(n):
        if edge[i][j]<=l:
            edge[i][j] = 1
        else:
            edge[i][j] = 0
                 i range(n) range n for j in range(n):
        if edge[i][j]<=l:
            edge[i][j] = 1
        else:
            edge[i][j] = 0
                 j range(n) range n if edge[i][j]<=l:
            edge[i][j] = 1
        else:
            edge[i][j] = 0
                 edge[i][j]<=l edge[i][j] [i] edge i j l edge[i][j] = 1 edge[i][j] [i] edge i j 1 edge[i][j] = 0 edge[i][j] [i] edge i j 0 edge = floyd_warshall(edge) edge floyd_warshall(edge) floyd_warshall edge q = int(input()) q int(input()) int input() input for i in range(q):
    s,t = map(int,input().split())
    if edge[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(edge[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 edge[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(edge[s-1][t-1] - 1)) edge[s-1][t-1] == float("inf") edge[s-1][t-1] [s-1] edge s-1 s 1 t-1 t 1 float("inf") float "inf" print(-1) print -1 print(int(edge[s-1][t-1] - 1)) print int(edge[s-1][t-1] - 1) int edge[s-1][t-1] - 1 edge[s-1][t-1] [s-1] edge s-1 s 1 t-1 t 1 1 edge = [[0]*n for _ in range(n)] [[0]*n for _ in range(n)] edge edge = floyd_warshall(edge) floyd_warshall(edge) edge m,l = map(int,input().split()) map(int,input().split()) m c = map(int,input().split()) map(int,input().split()) c q = int(input()) int(input()) q n,m,l = map(int,input().split()) map(int,input().split()) n l = map(int,input().split()) map(int,input().split()) l input = sys.stdin.readline sys.stdin.readline input edge = floyd_warshall(edge) floyd_warshall(edge) edge b,c = map(int,input().split()) map(int,input().split()) b t = map(int,input().split()) map(int,input().split()) t a,b,c = map(int,input().split()) map(int,input().split()) a s,t = map(int,input().split()) map(int,input().split()) s
import sys
input = sys.stdin.readline
from scipy.sparse.csgraph import floyd_warshall
      
n,m,l = map(int,input().split())
edge = [[0]*n for _ in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    edge[a-1][b-1] = c
    edge[b-1][a-1] = c

edge = floyd_warshall(edge)
    
for i in range(n):
    for j in range(n):
        if edge[i][j]<=l:
            edge[i][j] = 1
        else:
            edge[i][j] = 0
                
edge = floyd_warshall(edge)

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