from scipy.sparse.csgraph import floyd_warshall

N,M,L = map(int,input().split())
abc = [[int(i) for i in input().split()] for j in range(M)]
Q = int(input())
st = [[int(i) for i in input().split()] for j in range(Q)]
INF = 1<<30
Path = [[INF for i in range(N)] for j in range(N)]
AnsPath = [[INF for i in range(N)] for j in range(N)]

def PathInit():
    for i in range(N):
        Path[i][i] = 0

PathInit()
for i,j,k in abc:
    Path[i-1][j-1] = k
    #双方向
    Path[j-1][i-1] = k

Path = floyd_warshall(Path)

for i in range(N):
    for j in range(N):
        if Path[i][j] <= L:
            AnsPath[i][j] = 1
AnsPath = floyd_warshall(AnsPath)
for s,t in st:
    if AnsPath[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(AnsPath[s-1][t-1]-1)) 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 [int(i) for i in input().split()] for j in range(M) for j in range(M) j range(M) range M for j in range(M) [int(i) for i in input().split()] abc = [[int(i) for i in input().split()] for j in range(M)] abc [[int(i) for i in input().split()] for j in range(M)] Q = int(input()) Q int(input()) int input() input [int(i) for i in input().split()] for j in range(Q) for j in range(Q) j range(Q) range Q for j in range(Q) [int(i) for i in input().split()] st = [[int(i) for i in input().split()] for j in range(Q)] st [[int(i) for i in input().split()] for j in range(Q)] INF = 1<<30 INF 1<<30 1 30 [INF for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [INF for i in range(N)] Path = [[INF for i in range(N)] for j in range(N)] Path [[INF for i in range(N)] for j in range(N)] [INF for i in range(N)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [INF for i in range(N)] AnsPath = [[INF for i in range(N)] for j in range(N)] AnsPath [[INF for i in range(N)] for j in range(N)] def PathInit():
    for i in range(N):
        Path[i][i] = 0 PathInit for i in range(N):
        Path[i][i] = 0 i range(N) range N Path[i][i] = 0 Path[i][i] [i] Path i i 0 PathInit() PathInit for i,j,k in abc:
    Path[i-1][j-1] = k
    #双方向
    Path[j-1][i-1] = k i j k abc Path[i-1][j-1] = k Path[i-1][j-1] [i-1] Path i-1 i 1 j-1 j 1 k Path[j-1][i-1] = k Path[j-1][i-1] [j-1] Path j-1 j 1 i-1 i 1 k Path = floyd_warshall(Path) Path floyd_warshall(Path) floyd_warshall Path for i in range(N):
    for j in range(N):
        if Path[i][j] <= L:
            AnsPath[i][j] = 1 i range(N) range N for j in range(N):
        if Path[i][j] <= L:
            AnsPath[i][j] = 1 j range(N) range N if Path[i][j] <= L:
            AnsPath[i][j] = 1 Path[i][j] <= L Path[i][j] [i] Path i j L AnsPath[i][j] = 1 AnsPath[i][j] [i] AnsPath i j 1 AnsPath = floyd_warshall(AnsPath) AnsPath floyd_warshall(AnsPath) floyd_warshall AnsPath for s,t in st:
    if AnsPath[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(AnsPath[s-1][t-1]-1)) s t st if AnsPath[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(AnsPath[s-1][t-1]-1)) AnsPath[s-1][t-1] == INF AnsPath[s-1][t-1] [s-1] AnsPath s-1 s 1 t-1 t 1 INF print(-1) print -1 print(int(AnsPath[s-1][t-1]-1)) print int(AnsPath[s-1][t-1]-1) int AnsPath[s-1][t-1]-1 AnsPath[s-1][t-1] [s-1] AnsPath s-1 s 1 t-1 t 1 1 def PathInit():
    for i in range(N):
        Path[i][i] = 0 def PathInit():
    for i in range(N):
        Path[i][i] = 0 PathInit L = map(int,input().split()) map(int,input().split()) L abc = [[int(i) for i in input().split()] for j in range(M)] [[int(i) for i in input().split()] for j in range(M)] abc Q = int(input()) int(input()) Q st = [[int(i) for i in input().split()] for j in range(Q)] [[int(i) for i in input().split()] for j in range(Q)] st Path = [[INF for i in range(N)] for j in range(N)] [[INF for i in range(N)] for j in range(N)] Path Path = floyd_warshall(Path) floyd_warshall(Path) Path AnsPath = [[INF for i in range(N)] for j in range(N)] [[INF for i in range(N)] for j in range(N)] AnsPath N,M,L = map(int,input().split()) map(int,input().split()) N M,L = map(int,input().split()) map(int,input().split()) M INF = 1<<30 1<<30 INF AnsPath = floyd_warshall(AnsPath) floyd_warshall(AnsPath) AnsPath
from scipy.sparse.csgraph import floyd_warshall

N,M,L = map(int,input().split())
abc = [[int(i) for i in input().split()] for j in range(M)]
Q = int(input())
st = [[int(i) for i in input().split()] for j in range(Q)]
INF = 1<<30
Path = [[INF for i in range(N)] for j in range(N)]
AnsPath = [[INF for i in range(N)] for j in range(N)]

def PathInit():
    for i in range(N):
        Path[i][i] = 0

PathInit()
for i,j,k in abc:
    Path[i-1][j-1] = k
    #双方向
    Path[j-1][i-1] = k

Path = floyd_warshall(Path)

for i in range(N):
    for j in range(N):
        if Path[i][j] <= L:
            AnsPath[i][j] = 1
AnsPath = floyd_warshall(AnsPath)
for s,t in st:
    if AnsPath[s-1][t-1] == INF:
        print(-1)
    else:
        print(int(AnsPath[s-1][t-1]-1))