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

for _ in range(M):
    A,B,C = map(int,input().split())
    D[A-1][B-1] = C
    D[B-1][A-1] = C

for k in range(N):
    for i in range(N-1):
        for j in range(i+1,N):
            D[i][j] = min(D[i][j],D[i][k]+D[j][k])
            D[j][i] = D[i][j]

F = [[INF]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i==j:
            F[i][j] = 0
        elif D[i][j] <= L:
            F[i][j] = 1

for k in range(N):
    for i in range(N-1):
        for j in range(i+1,N):
            F[i][j] = min(F[i][j],F[i][k]+F[j][k])
            F[j][i] = F[i][j]

for i in range(N):
    for j in range(N):
        if F[i][j] == INF:
            F[i][j] = -1
        elif i != j:
            F[i][j] -= 1

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

for _ in range(M):
    A,B,C = map(int,input().split())
    D[A-1][B-1] = C
    D[B-1][A-1] = C

for k in range(N):
    for i in range(N-1):
        for j in range(i+1,N):
            D[i][j] = min(D[i][j],D[i][k]+D[j][k])
            D[j][i] = D[i][j]

F = [[INF]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i==j:
            F[i][j] = 0
        elif D[i][j] <= L:
            F[i][j] = 1

for k in range(N):
    for i in range(N-1):
        for j in range(i+1,N):
            F[i][j] = min(F[i][j],F[i][k]+F[j][k])
            F[j][i] = F[i][j]

for i in range(N):
    for j in range(N):
        if F[i][j] == INF:
            F[i][j] = -1
        elif i != j:
            F[i][j] -= 1

Q = int(input())
for i in range(Q):
    s,t = map(int,input().split())
    print(F[s-1][t-1])

