import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

def main():
    N,M,L = map(int,input().split())
    edge = np.zeros((N,N))
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
        
    length = floyd_warshall(edge,directed=False)
    ref = np.where(length<=L,1,0)
    ans = floyd_warshall(ref,directed=False)
    Q = int(input())
    for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1)

if __name__ == "__main__":
    main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall def main():
    N,M,L = map(int,input().split())
    edge = np.zeros((N,N))
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
        
    length = floyd_warshall(edge,directed=False)
    ref = np.where(length<=L,1,0)
    ans = floyd_warshall(ref,directed=False)
    Q = int(input())
    for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1) main N,M,L = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L edge = np.zeros((N,N)) edge np.zeros((N,N)) np.zeros np zeros (N,N) N N for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = 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 edge[a-1][b-1] = edge[b-1][a-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 length = floyd_warshall(edge,directed=False) length floyd_warshall(edge,directed=False) floyd_warshall edge directed=False directed False ref = np.where(length<=L,1,0) ref np.where(length<=L,1,0) np.where np where length<=L length L 1 0 ans = floyd_warshall(ref,directed=False) ans floyd_warshall(ref,directed=False) floyd_warshall ref directed=False directed False Q = int(input()) Q int(input()) int input() input for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1) _ range(Q) range Q s,t = map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1) ans[s-1][t-1] == float("inf") ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 float("inf") float "inf" print(-1) print -1 print(int(ans[s-1][t-1])-1) print int(ans[s-1][t-1])-1 int(ans[s-1][t-1]) int ans[s-1][t-1] [s-1] ans s-1 s 1 t-1 t 1 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N,M,L = map(int,input().split())
    edge = np.zeros((N,N))
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
        
    length = floyd_warshall(edge,directed=False)
    ref = np.where(length<=L,1,0)
    ans = floyd_warshall(ref,directed=False)
    Q = int(input())
    for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1) def main():
    N,M,L = map(int,input().split())
    edge = np.zeros((N,N))
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
        
    length = floyd_warshall(edge,directed=False)
    ref = np.where(length<=L,1,0)
    ans = floyd_warshall(ref,directed=False)
    Q = int(input())
    for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1) main input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

def main():
    N,M,L = map(int,input().split())
    edge = np.zeros((N,N))
    for _ in range(M):
        a,b,c = map(int,input().split())
        edge[a-1][b-1] = edge[b-1][a-1] = c
        
    length = floyd_warshall(edge,directed=False)
    ref = np.where(length<=L,1,0)
    ans = floyd_warshall(ref,directed=False)
    Q = int(input())
    for _ in range(Q):
        s,t = map(int,input().split())
        if ans[s-1][t-1] == float("inf"):
            print(-1)
        else:
            print(int(ans[s-1][t-1])-1)

if __name__ == "__main__":
    main()
