import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M, L = map(int, rl().split())
    INF = 10 ** 18
    dist = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, rl().split())
        a, b = a - 1, b - 1
        dist[a][b] = dist[b][a] = c
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
    Q = int(rl())
    st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)]
    ans = [-1] * Q
    for i, (s, t) in enumerate(st):
        if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve() import sys sys sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 rl = sys.stdin.readline rl sys.stdin.readline sys.stdin sys stdin readline def solve():
    N, M, L = map(int, rl().split())
    INF = 10 ** 18
    dist = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, rl().split())
        a, b = a - 1, b - 1
        dist[a][b] = dist[b][a] = c
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
    Q = int(rl())
    st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)]
    ans = [-1] * Q
    for i, (s, t) in enumerate(st):
        if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
    print(*ans, sep='\n') solve N, M, L = map(int, rl().split()) N map(int, rl().split()) map int rl().split() ().split () rl split M L INF = 10 ** 18 INF 10 ** 18 10 18 [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N dist = [[INF] * N for _ in range(N)] dist [[INF] * N for _ in range(N)] for _ in range(M):
        a, b, c = map(int, rl().split())
        a, b = a - 1, b - 1
        dist[a][b] = dist[b][a] = c
    
     _ range(M) range M a, b, c = map(int, rl().split()) a map(int, rl().split()) map int rl().split() ().split () rl split b c a, b = a - 1, b - 1 a a - 1 a 1 b b - 1 b 1 dist[a][b] = dist[b][a] = c dist[a][b] [a] dist a b c = dist[b][a] = c dist[b][a] [b] dist b a c for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
     k range(N) range N for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
     i range(N) range N for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
     j range(N) range N dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) dist[i][j] [i] dist i j min(dist[i][j], dist[i][k] + dist[k][j]) min dist[i][j] [i] dist i j dist[i][k] + dist[k][j] dist[i][k] [i] dist i k dist[k][j] [k] dist k j [INF] * N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF] * N [INF] INF N cost = [[INF] * N for _ in range(N)] cost [[INF] * N for _ in range(N)] for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
     i range(N) range N for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
     j range(N) range N if dist[i][j] <= L:
                cost[i][j] = 1
    
     dist[i][j] <= L dist[i][j] [i] dist i j L cost[i][j] = 1 cost[i][j] [i] cost i j 1 for k in range(N):
        for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
     k range(N) range N for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
     i range(N) range N for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
     j range(N) range N cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]) cost[i][j] [i] cost i j min(cost[i][j], cost[i][k] + cost[k][j]) min cost[i][j] [i] cost i j cost[i][k] + cost[k][j] cost[i][k] [i] cost i k cost[k][j] [k] cost k j Q = int(rl()) Q int(rl()) int rl() rl list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q) for _ in range(Q) _ range(Q) range Q for _ in range(Q) list(map(lambda n: int(n) - 1, rl().split())) list map(lambda n: int(n) - 1, rl().split()) map lambda n: int(n) - 1 int(n) - 1 int(n) int n 1 n rl().split() ().split () rl split st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)] st [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)] ans = [-1] * Q ans [-1] * Q [-1] -1 Q for i, (s, t) in enumerate(st):
        if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
     i (s, t) s t enumerate(st) enumerate st if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
     cost[s][t] != INF cost[s][t] [s] cost s t INF ans[i] = cost[s][t] - 1 ans[i] ans i cost[s][t] - 1 cost[s][t] [s] cost s t 1 print(*ans, sep='\n') print *ans ans sep='\n' sep '\n' if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def solve():
    N, M, L = map(int, rl().split())
    INF = 10 ** 18
    dist = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, rl().split())
        a, b = a - 1, b - 1
        dist[a][b] = dist[b][a] = c
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
    Q = int(rl())
    st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)]
    ans = [-1] * Q
    for i, (s, t) in enumerate(st):
        if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
    print(*ans, sep='\n') def solve():
    N, M, L = map(int, rl().split())
    INF = 10 ** 18
    dist = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, rl().split())
        a, b = a - 1, b - 1
        dist[a][b] = dist[b][a] = c
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
    Q = int(rl())
    st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)]
    ans = [-1] * Q
    for i, (s, t) in enumerate(st):
        if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
    print(*ans, sep='\n') solve rl = sys.stdin.readline sys.stdin.readline rl
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M, L = map(int, rl().split())
    INF = 10 ** 18
    dist = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, rl().split())
        a, b = a - 1, b - 1
        dist[a][b] = dist[b][a] = c
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    
    cost = [[INF] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                cost[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
    
    Q = int(rl())
    st = [list(map(lambda n: int(n) - 1, rl().split())) for _ in range(Q)]
    ans = [-1] * Q
    for i, (s, t) in enumerate(st):
        if cost[s][t] != INF:
            ans[i] = cost[s][t] - 1
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()
