import sys
input = sys.stdin.readline

def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


N, M, L = map(int, input().split())
INF = 10 ** 10
d = [[INF for _ in range(N)] for _ in range(N)]
D = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    d[i][i] = 0
for i in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    d[A][B] = C
    d[B][A] = C
d = warshall_floyd(d)

for i in range(N):
    for j in range(N):
        if 0 < d[i][j] <= L:
            D[i][j] = 1
        elif d[i][j] == 0:
            D[i][j] = 0
D = warshall_floyd(D)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(D[s][t] - 1 if D[s][t] != INF else -1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d warshall_floyd for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     k range(N) range N for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     i range(N) range N for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
     j range(N) range N d[i][j] = min(d[i][j], d[i][k] + d[k][j]) d[i][j] [i] d i j min(d[i][j], d[i][k] + d[k][j]) min d[i][j] [i] d i j d[i][k] + d[k][j] d[i][k] [i] d i k d[k][j] [k] d k j return d d d d N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L INF = 10 ** 10 INF 10 ** 10 10 10 [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] d = [[INF for _ in range(N)] for _ in range(N)] d [[INF for _ in range(N)] for _ in range(N)] [INF for _ in range(N)] for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [INF for _ in range(N)] D = [[INF for _ in range(N)] for _ in range(N)] D [[INF for _ in range(N)] for _ in range(N)] for i in range(N):
    d[i][i] = 0 i range(N) range N d[i][i] = 0 d[i][i] [i] d i i 0 for i in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    d[A][B] = C
    d[B][A] = C i 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 d[A][B] = C d[A][B] [A] d A B C d[B][A] = C d[B][A] [B] d B A C d = warshall_floyd(d) d warshall_floyd(d) warshall_floyd d for i in range(N):
    for j in range(N):
        if 0 < d[i][j] <= L:
            D[i][j] = 1
        elif d[i][j] == 0:
            D[i][j] = 0 i range(N) range N for j in range(N):
        if 0 < d[i][j] <= L:
            D[i][j] = 1
        elif d[i][j] == 0:
            D[i][j] = 0 j range(N) range N if 0 < d[i][j] <= L:
            D[i][j] = 1
        elif d[i][j] == 0:
            D[i][j] = 0 0 < d[i][j] <= L 0 < d[i][j] 0 d[i][j] [i] d i j L D[i][j] = 1 D[i][j] [i] D i j 1 elif d[i][j] == 0:
            D[i][j] = 0 d[i][j] == 0 d[i][j] [i] d i j 0 D[i][j] = 0 D[i][j] [i] D i j 0 D = warshall_floyd(D) D warshall_floyd(D) warshall_floyd D Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(D[s][t] - 1 if D[s][t] != INF else -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(D[s][t] - 1 if D[s][t] != INF else -1) print D[s][t] - 1 if D[s][t] != INF else -1 D[s][t] != INF D[s][t] [s] D s t INF D[s][t] - 1 D[s][t] [s] D s t 1 -1 input = sys.stdin.readline sys.stdin.readline input s -= 1 1 s B, C = map(int, input().split()) map(int, input().split()) B d = [[INF for _ in range(N)] for _ in range(N)] [[INF for _ in range(N)] for _ in range(N)] d INF = 10 ** 10 10 ** 10 INF t = map(int, input().split()) map(int, input().split()) t C = map(int, input().split()) map(int, input().split()) C M, L = map(int, input().split()) map(int, input().split()) M N, M, L = map(int, input().split()) map(int, input().split()) N def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d warshall_floyd s, t = map(int, input().split()) map(int, input().split()) s Q = int(input()) int(input()) Q L = map(int, input().split()) map(int, input().split()) L D = warshall_floyd(D) warshall_floyd(D) D D = [[INF for _ in range(N)] for _ in range(N)] [[INF for _ in range(N)] for _ in range(N)] D t -= 1 1 t A -= 1 1 A A, B, C = map(int, input().split()) map(int, input().split()) A d = warshall_floyd(d) warshall_floyd(d) d B -= 1 1 B
import sys
input = sys.stdin.readline

def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


N, M, L = map(int, input().split())
INF = 10 ** 10
d = [[INF for _ in range(N)] for _ in range(N)]
D = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    d[i][i] = 0
for i in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    d[A][B] = C
    d[B][A] = C
d = warshall_floyd(d)

for i in range(N):
    for j in range(N):
        if 0 < d[i][j] <= L:
            D[i][j] = 1
        elif d[i][j] == 0:
            D[i][j] = 0
D = warshall_floyd(D)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(D[s][t] - 1 if D[s][t] != INF else -1)
