import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N,M,L = map(int,input().split())
gurahu = np.zeros((N,N))

for k in range(M):
    a,b,c = map(int,input().split())
    gurahu[a-1,b-1] = c
    gurahu[b-1,a-1] = c

gurahu = floyd_warshall(gurahu, directed=False)
gurahu = np.where((gurahu <= L) & (gurahu > 0), 1, 0)
gurahu = floyd_warshall(gurahu) - np.ones((N, N))

Q = int(input())

for k in range(Q):
    s,t = map(int,input().split())
    ans = gurahu[s-1,t-1]
    if ans == float('inf'):
        print(-1)
    else:
        print(int(ans)) import numpy as np numpy 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 gurahu = np.zeros((N,N)) gurahu np.zeros((N,N)) np.zeros np zeros (N,N) N N for k in range(M):
    a,b,c = map(int,input().split())
    gurahu[a-1,b-1] = c
    gurahu[b-1,a-1] = c k 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 gurahu[a-1,b-1] = c gurahu[a-1,b-1] gurahu a-1 a 1 c gurahu[b-1,a-1] = c gurahu[b-1,a-1] gurahu b-1 b 1 c gurahu = floyd_warshall(gurahu, directed=False) gurahu floyd_warshall(gurahu, directed=False) floyd_warshall gurahu directed=False directed False gurahu = np.where((gurahu <= L) & (gurahu > 0), 1, 0) gurahu np.where((gurahu <= L) & (gurahu > 0), 1, 0) np.where np where (gurahu <= L) & (gurahu > 0) gurahu <= L gurahu L gurahu > 0 gurahu 0 1 0 gurahu = floyd_warshall(gurahu) - np.ones((N, N)) gurahu floyd_warshall(gurahu) - np.ones((N, N)) floyd_warshall(gurahu) floyd_warshall gurahu np.ones((N, N)) np.ones np ones (N, N) N N Q = int(input()) Q int(input()) int input() input for k in range(Q):
    s,t = map(int,input().split())
    ans = gurahu[s-1,t-1]
    if ans == float('inf'):
        print(-1)
    else:
        print(int(ans)) k range(Q) range Q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t ans = gurahu[s-1,t-1] ans gurahu[s-1,t-1] gurahu s-1 s 1 if ans == float('inf'):
        print(-1)
    else:
        print(int(ans)) ans == float('inf') ans float('inf') float 'inf' print(-1) print -1 print(int(ans)) print int(ans) int ans b,c = map(int,input().split()) map(int,input().split()) b gurahu = np.zeros((N,N)) np.zeros((N,N)) gurahu gurahu = floyd_warshall(gurahu) - np.ones((N, N)) floyd_warshall(gurahu) - np.ones((N, N)) gurahu N,M,L = map(int,input().split()) map(int,input().split()) N a,b,c = map(int,input().split()) map(int,input().split()) a gurahu = floyd_warshall(gurahu, directed=False) floyd_warshall(gurahu, directed=False) gurahu M,L = map(int,input().split()) map(int,input().split()) M ans = gurahu[s-1,t-1] gurahu[s-1,t-1] ans c = map(int,input().split()) map(int,input().split()) c gurahu = np.where((gurahu <= L) & (gurahu > 0), 1, 0) np.where((gurahu <= L) & (gurahu > 0), 1, 0) gurahu s,t = map(int,input().split()) map(int,input().split()) s Q = int(input()) int(input()) Q t = map(int,input().split()) map(int,input().split()) t L = map(int,input().split()) map(int,input().split()) L
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

N,M,L = map(int,input().split())
gurahu = np.zeros((N,N))

for k in range(M):
    a,b,c = map(int,input().split())
    gurahu[a-1,b-1] = c
    gurahu[b-1,a-1] = c

gurahu = floyd_warshall(gurahu, directed=False)
gurahu = np.where((gurahu <= L) & (gurahu > 0), 1, 0)
gurahu = floyd_warshall(gurahu) - np.ones((N, N))

Q = int(input())

for k in range(Q):
    s,t = map(int,input().split())
    ans = gurahu[s-1,t-1]
    if ans == float('inf'):
        print(-1)
    else:
        print(int(ans))