MOD = 10 **9 + 7
INF = 10 ** 10
import numpy as np
from  scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

def main():
    n,m,l = map(int,input().split())
    dist = [[np.inf] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    csr = csr_matrix(dist)
    dist1 = floyd_warshall(csr,directed = False)
    dist1 = np.where(dist1 <= l,1,np.inf)
    cnt = floyd_warshall(dist1,directed = False)
    cnt[cnt == np.inf] = 0
    cnt = cnt.astype(int)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1)
if __name__ == '__main__':
    main() MOD = 10 **9 + 7 MOD 10 **9 + 7 10 **9 10 9 7 INF = 10 ** 10 INF 10 ** 10 10 10 import numpy as np numpy from  scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix def main():
    n,m,l = map(int,input().split())
    dist = [[np.inf] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    csr = csr_matrix(dist)
    dist1 = floyd_warshall(csr,directed = False)
    dist1 = np.where(dist1 <= l,1,np.inf)
    cnt = floyd_warshall(dist1,directed = False)
    cnt[cnt == np.inf] = 0
    cnt = cnt.astype(int)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1) main n,m,l = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l [np.inf] * n for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [np.inf] * n [np.inf] np.inf np inf n dist = [[np.inf] * n for _ in range(n)] dist [[np.inf] * n for _ in range(n)] for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

     _ 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 a -= 1 a 1 b -= 1 b 1 dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c csr = csr_matrix(dist) csr csr_matrix(dist) csr_matrix dist dist1 = floyd_warshall(csr,directed = False) dist1 floyd_warshall(csr,directed = False) floyd_warshall csr directed = False directed False dist1 = np.where(dist1 <= l,1,np.inf) dist1 np.where(dist1 <= l,1,np.inf) np.where np where dist1 <= l dist1 l 1 np.inf np inf cnt = floyd_warshall(dist1,directed = False) cnt floyd_warshall(dist1,directed = False) floyd_warshall dist1 directed = False directed False cnt[cnt == np.inf] = 0 cnt[cnt == np.inf] cnt cnt == np.inf cnt np.inf np inf 0 cnt = cnt.astype(int) cnt cnt.astype(int) cnt.astype cnt astype int q = int(input()) q int(input()) int input() input for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1) _ range(q) range q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t s -= 1 s 1 t -= 1 t 1 print(cnt[s][t] - 1) print cnt[s][t] - 1 cnt[s][t] [s] cnt s t 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n,m,l = map(int,input().split())
    dist = [[np.inf] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    csr = csr_matrix(dist)
    dist1 = floyd_warshall(csr,directed = False)
    dist1 = np.where(dist1 <= l,1,np.inf)
    cnt = floyd_warshall(dist1,directed = False)
    cnt[cnt == np.inf] = 0
    cnt = cnt.astype(int)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1) def main():
    n,m,l = map(int,input().split())
    dist = [[np.inf] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    csr = csr_matrix(dist)
    dist1 = floyd_warshall(csr,directed = False)
    dist1 = np.where(dist1 <= l,1,np.inf)
    cnt = floyd_warshall(dist1,directed = False)
    cnt[cnt == np.inf] = 0
    cnt = cnt.astype(int)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1) main MOD = 10 **9 + 7 10 **9 + 7 MOD INF = 10 ** 10 10 ** 10 INF
MOD = 10 **9 + 7
INF = 10 ** 10
import numpy as np
from  scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

def main():
    n,m,l = map(int,input().split())
    dist = [[np.inf] * n for _ in range(n)]  
    for _ in range(m):
        a,b,c = map(int,input().split())
        a -= 1
        b -= 1
        dist[a][b] = c
        dist[b][a] = c

    csr = csr_matrix(dist)
    dist1 = floyd_warshall(csr,directed = False)
    dist1 = np.where(dist1 <= l,1,np.inf)
    cnt = floyd_warshall(dist1,directed = False)
    cnt[cnt == np.inf] = 0
    cnt = cnt.astype(int)
    q = int(input())
    for _ in range(q):
        s,t = map(int,input().split())
        s -= 1
        t -= 1
        print(cnt[s][t] - 1)
if __name__ == '__main__':
    main()