import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
def warshall_floyd(N, edges,
                   nopath=None,
                   start_distance=0,
                   plus_func=lambda D,d: D+d):
    '''
    edges: list of set
        edges = [{(y0, distance0), (y1, distance1), ...}, ...]
    '''
    ret = [[nopath]*N for _ in range(N)]
    for i in range(N):
        ret[i][i] = start_distance
    for i in range(N):
        for j, d in edges[i]:
            if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
    for k in range(N):
        for i in range(N):
            if i == k: continue
            for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
    return ret

N, M, L = inpl()
road = [[] for _ in range(N)]
for i in range(M):
    A, B, C = inpl()
    if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C))

Q = int(input())
ST = []
goals = [set() for _ in range(N)]
for _ in range(Q):
    s, t = inpl()
    s -= 1
    t -= 1
    ST.append((s, t))

distance = warshall_floyd(N, road)
path = [set() for _ in range(N)]
for i in range(N):
    for j in range(N):
        d = distance[i][j]
        if d is not None and d <= L:
            path[i].add((j,1))
ans = warshall_floyd(N, path)
for s, t in ST:
    if ans[s][t] is None:
        print(-1)
    else:
        print(ans[s][t]-1) import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip inpl = lambda: list(map(int,input().split())) inpl lambda: list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def warshall_floyd(N, edges,
                   nopath=None,
                   start_distance=0,
                   plus_func=lambda D,d: D+d):
    '''
    edges: list of set
        edges = [{(y0, distance0), (y1, distance1), ...}, ...]
    '''
    ret = [[nopath]*N for _ in range(N)]
    for i in range(N):
        ret[i][i] = start_distance
    for i in range(N):
        for j, d in edges[i]:
            if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
    for k in range(N):
        for i in range(N):
            if i == k: continue
            for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
    return ret warshall_floyd '''
    edges: list of set
        edges = [{(y0, distance0), (y1, distance1), ...}, ...]
    ''' [nopath]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [nopath]*N [nopath] nopath N ret = [[nopath]*N for _ in range(N)] ret [[nopath]*N for _ in range(N)] for i in range(N):
        ret[i][i] = start_distance
     i range(N) range N ret[i][i] = start_distance ret[i][i] [i] ret i i start_distance for i in range(N):
        for j, d in edges[i]:
            if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
     i range(N) range N for j, d in edges[i]:
            if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
     j d edges[i] edges i if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
     0 <= j < N 0 <= j 0 j N ret[i][j] = plus_func(start_distance, d) ret[i][j] [i] ret i j plus_func(start_distance, d) plus_func start_distance d for k in range(N):
        for i in range(N):
            if i == k: continue
            for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
     k range(N) range N for i in range(N):
            if i == k: continue
            for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
     i range(N) range N if i == k: continue
             i == k i k for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
     j range(N) range N if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                 j == k or ret[i][k] == nopath or ret[k][j] == nopath j == k or ret[i][k] == nopath j == k j k ret[i][k] == nopath ret[i][k] [i] ret i k nopath ret[k][j] == nopath ret[k][j] [k] ret k j nopath continue d = plus_func(ret[i][k], ret[k][j]) d plus_func(ret[i][k], ret[k][j]) plus_func ret[i][k] [i] ret i k ret[k][j] [k] ret k j if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
     ret[i][j] == nopath or d < ret[i][j] ret[i][j] == nopath ret[i][j] [i] ret i j nopath d < ret[i][j] d ret[i][j] [i] ret i j ret[i][j] = d ret[i][j] [i] ret i j d return ret ret N N edges edges nopath=None nopath None start_distance=0 start_distance 0 plus_func=lambda D,d: D+d plus_func lambda D,d: D+d D+d D d D d N, M, L = inpl() N inpl() inpl M L [] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [] road = [[] for _ in range(N)] road [[] for _ in range(N)] for i in range(M):
    A, B, C = inpl()
    if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C)) i range(M) range M A, B, C = inpl() A inpl() inpl B C if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C)) C <= L C L road[A-1].append((B-1,C)) [A-1].append [A-1] road A-1 A 1 append (B-1,C) B-1 B 1 C road[B-1].append((A-1,C)) [B-1].append [B-1] road B-1 B 1 append (A-1,C) A-1 A 1 C Q = int(input()) Q int(input()) int input() input ST = [] ST [] set() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) set() set goals = [set() for _ in range(N)] goals [set() for _ in range(N)] for _ in range(Q):
    s, t = inpl()
    s -= 1
    t -= 1
    ST.append((s, t)) _ range(Q) range Q s, t = inpl() s inpl() inpl t s -= 1 s 1 t -= 1 t 1 ST.append((s, t)) ST.append ST append (s, t) s t distance = warshall_floyd(N, road) distance warshall_floyd(N, road) warshall_floyd N road set() for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) set() set path = [set() for _ in range(N)] path [set() for _ in range(N)] for i in range(N):
    for j in range(N):
        d = distance[i][j]
        if d is not None and d <= L:
            path[i].add((j,1)) i range(N) range N for j in range(N):
        d = distance[i][j]
        if d is not None and d <= L:
            path[i].add((j,1)) j range(N) range N d = distance[i][j] d distance[i][j] [i] distance i j if d is not None and d <= L:
            path[i].add((j,1)) d is not None and d <= L d is not None d None d <= L d L path[i].add((j,1)) [i].add [i] path i add (j,1) j 1 ans = warshall_floyd(N, path) ans warshall_floyd(N, path) warshall_floyd N path for s, t in ST:
    if ans[s][t] is None:
        print(-1)
    else:
        print(ans[s][t]-1) s t ST if ans[s][t] is None:
        print(-1)
    else:
        print(ans[s][t]-1) ans[s][t] is None ans[s][t] [s] ans s t None print(-1) print -1 print(ans[s][t]-1) print ans[s][t]-1 ans[s][t] [s] ans s t 1 d = distance[i][j] distance[i][j] d M, L = inpl() inpl() M t -= 1 1 t s, t = inpl() inpl() s L = inpl() inpl() L input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input path = [set() for _ in range(N)] [set() for _ in range(N)] path t = inpl() inpl() t s -= 1 1 s road = [[] for _ in range(N)] [[] for _ in range(N)] road N, M, L = inpl() inpl() N A, B, C = inpl() inpl() A Q = int(input()) int(input()) Q ST = [] [] ST B, C = inpl() inpl() B distance = warshall_floyd(N, road) warshall_floyd(N, road) distance ans = warshall_floyd(N, path) warshall_floyd(N, path) ans inpl = lambda: list(map(int,input().split())) lambda: list(map(int,input().split())) inpl C = inpl() inpl() C def warshall_floyd(N, edges,
                   nopath=None,
                   start_distance=0,
                   plus_func=lambda D,d: D+d):
    '''
    edges: list of set
        edges = [{(y0, distance0), (y1, distance1), ...}, ...]
    '''
    ret = [[nopath]*N for _ in range(N)]
    for i in range(N):
        ret[i][i] = start_distance
    for i in range(N):
        for j, d in edges[i]:
            if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
    for k in range(N):
        for i in range(N):
            if i == k: continue
            for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
    return ret def warshall_floyd(N, edges,
                   nopath=None,
                   start_distance=0,
                   plus_func=lambda D,d: D+d):
    '''
    edges: list of set
        edges = [{(y0, distance0), (y1, distance1), ...}, ...]
    '''
    ret = [[nopath]*N for _ in range(N)]
    for i in range(N):
        ret[i][i] = start_distance
    for i in range(N):
        for j, d in edges[i]:
            if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
    for k in range(N):
        for i in range(N):
            if i == k: continue
            for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
    return ret warshall_floyd goals = [set() for _ in range(N)] [set() for _ in range(N)] goals
import sys
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
def warshall_floyd(N, edges,
                   nopath=None,
                   start_distance=0,
                   plus_func=lambda D,d: D+d):
    '''
    edges: list of set
        edges = [{(y0, distance0), (y1, distance1), ...}, ...]
    '''
    ret = [[nopath]*N for _ in range(N)]
    for i in range(N):
        ret[i][i] = start_distance
    for i in range(N):
        for j, d in edges[i]:
            if 0 <= j < N:
                ret[i][j] = plus_func(start_distance, d)
    for k in range(N):
        for i in range(N):
            if i == k: continue
            for j in range(N):
                if j == k or ret[i][k] == nopath or ret[k][j] == nopath:
                    continue
                d = plus_func(ret[i][k], ret[k][j])
                if ret[i][j] == nopath or d < ret[i][j]:
                    ret[i][j] = d
    return ret

N, M, L = inpl()
road = [[] for _ in range(N)]
for i in range(M):
    A, B, C = inpl()
    if C <= L:
        road[A-1].append((B-1,C))
        road[B-1].append((A-1,C))

Q = int(input())
ST = []
goals = [set() for _ in range(N)]
for _ in range(Q):
    s, t = inpl()
    s -= 1
    t -= 1
    ST.append((s, t))

distance = warshall_floyd(N, road)
path = [set() for _ in range(N)]
for i in range(N):
    for j in range(N):
        d = distance[i][j]
        if d is not None and d <= L:
            path[i].add((j,1))
ans = warshall_floyd(N, path)
for s, t in ST:
    if ans[s][t] is None:
        print(-1)
    else:
        print(ans[s][t]-1)
