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


def solve(N,L,edges,queries):

    graph = np.zeros((N,N),dtype=int)
    for a,b,c in edges:
        graph[a-1,b-1] = c
        graph[b-1,a-1] = c

    dist = floyd_warshall(graph, directed=False)
    dist = (dist<=L)
    dist = floyd_warshall(dist, directed=False)
    res = []
    for a,b in queries:
        d = dist[a-1,b-1]
        res.append(int(d-1) if d != float('inf') else -1)
    return res

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

if __name__ == '__main__':

    t = read().split()

    N,M,L = map(int,t[:3])

    m = map(int,t[3:M*3+3])
    edges = zip(m,m,m)

    Q = int(t[M*3+3])
    m = map(int, t[M*3+4:])
    queries = zip(m,m)

    print(*solve(N,L,edges,queries), sep='\n') import numpy as np numpy from scipy.sparse.csgraph import floyd_warshall def solve(N,L,edges,queries):

    graph = np.zeros((N,N),dtype=int)
    for a,b,c in edges:
        graph[a-1,b-1] = c
        graph[b-1,a-1] = c

    dist = floyd_warshall(graph, directed=False)
    dist = (dist<=L)
    dist = floyd_warshall(dist, directed=False)
    res = []
    for a,b in queries:
        d = dist[a-1,b-1]
        res.append(int(d-1) if d != float('inf') else -1)
    return res solve graph = np.zeros((N,N),dtype=int) graph np.zeros((N,N),dtype=int) np.zeros np zeros (N,N) N N dtype=int dtype int for a,b,c in edges:
        graph[a-1,b-1] = c
        graph[b-1,a-1] = c

     a b c edges graph[a-1,b-1] = c graph[a-1,b-1] graph a-1 a 1 c graph[b-1,a-1] = c graph[b-1,a-1] graph b-1 b 1 c dist = floyd_warshall(graph, directed=False) dist floyd_warshall(graph, directed=False) floyd_warshall graph directed=False directed False dist = (dist<=L) dist dist<=L dist L dist = floyd_warshall(dist, directed=False) dist floyd_warshall(dist, directed=False) floyd_warshall dist directed=False directed False res = [] res [] for a,b in queries:
        d = dist[a-1,b-1]
        res.append(int(d-1) if d != float('inf') else -1)
     a b queries d = dist[a-1,b-1] d dist[a-1,b-1] dist a-1 a 1 res.append(int(d-1) if d != float('inf') else -1) res.append res append int(d-1) if d != float('inf') else -1 d != float('inf') d float('inf') float 'inf' int(d-1) int d-1 d 1 -1 return res res N N L L edges edges queries queries import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline if __name__ == '__main__':

    t = read().split()

    N,M,L = map(int,t[:3])

    m = map(int,t[3:M*3+3])
    edges = zip(m,m,m)

    Q = int(t[M*3+3])
    m = map(int, t[M*3+4:])
    queries = zip(m,m)

    print(*solve(N,L,edges,queries), sep='\n') __name__ == '__main__' __name__ '__main__' t = read().split() t read().split() ().split () read split N,M,L = map(int,t[:3]) N map(int,t[:3]) map int t[:3] t :3 3 M L m = map(int,t[3:M*3+3]) m map(int,t[3:M*3+3]) map int t[3:M*3+3] t 3:M*3+3 3 M*3+3 M*3 M 3 3 edges = zip(m,m,m) edges zip(m,m,m) zip m m m Q = int(t[M*3+3]) Q int(t[M*3+3]) int t[M*3+3] t M*3+3 M*3 M 3 3 m = map(int, t[M*3+4:]) m map(int, t[M*3+4:]) map int t[M*3+4:] t M*3+4: M*3+4 M*3 M 3 4 queries = zip(m,m) queries zip(m,m) zip m m print(*solve(N,L,edges,queries), sep='\n') print *solve(N,L,edges,queries) solve(N,L,edges,queries) solve N L edges queries sep='\n' sep '\n' M,L = map(int,t[:3]) map(int,t[:3]) M m = map(int,t[3:M*3+3]) map(int,t[3:M*3+3]) m m = map(int, t[M*3+4:]) map(int, t[M*3+4:]) m L = map(int,t[:3]) map(int,t[:3]) L edges = zip(m,m,m) zip(m,m,m) edges t = read().split() read().split() t def solve(N,L,edges,queries):

    graph = np.zeros((N,N),dtype=int)
    for a,b,c in edges:
        graph[a-1,b-1] = c
        graph[b-1,a-1] = c

    dist = floyd_warshall(graph, directed=False)
    dist = (dist<=L)
    dist = floyd_warshall(dist, directed=False)
    res = []
    for a,b in queries:
        d = dist[a-1,b-1]
        res.append(int(d-1) if d != float('inf') else -1)
    return res def solve(N,L,edges,queries):

    graph = np.zeros((N,N),dtype=int)
    for a,b,c in edges:
        graph[a-1,b-1] = c
        graph[b-1,a-1] = c

    dist = floyd_warshall(graph, directed=False)
    dist = (dist<=L)
    dist = floyd_warshall(dist, directed=False)
    res = []
    for a,b in queries:
        d = dist[a-1,b-1]
        res.append(int(d-1) if d != float('inf') else -1)
    return res solve read = sys.stdin.buffer.read sys.stdin.buffer.read read N,M,L = map(int,t[:3]) map(int,t[:3]) N Q = int(t[M*3+3]) int(t[M*3+3]) Q queries = zip(m,m) zip(m,m) queries readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
import numpy as np
from scipy.sparse.csgraph import floyd_warshall


def solve(N,L,edges,queries):

    graph = np.zeros((N,N),dtype=int)
    for a,b,c in edges:
        graph[a-1,b-1] = c
        graph[b-1,a-1] = c

    dist = floyd_warshall(graph, directed=False)
    dist = (dist<=L)
    dist = floyd_warshall(dist, directed=False)
    res = []
    for a,b in queries:
        d = dist[a-1,b-1]
        res.append(int(d-1) if d != float('inf') else -1)
    return res

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

if __name__ == '__main__':

    t = read().split()

    N,M,L = map(int,t[:3])

    m = map(int,t[3:M*3+3])
    edges = zip(m,m,m)

    Q = int(t[M*3+3])
    m = map(int, t[M*3+4:])
    queries = zip(m,m)

    print(*solve(N,L,edges,queries), sep='\n')