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])
 
N, M, L = map(int, input().split())
D1 = [[10**18]*N for _ in range(N)]
 
for i in range(N):
    D1[i][i] = 0
 
for _ in range(M):
    A, B, C = map(int, input().split())
    D1[A-1][B-1] = C
    D1[B-1][A-1] = C

warshall_floyd(D1)
D2 = [[10**18]*N for _ in range(N)]

for i in range(N):
    D2[i][i] = 0
    
for i in range(N):
    for j in range(N):
        if i!=j and D1[i][j]<=L:
            D2[i][j] = 1

warshall_floyd(D2)
Q = int(input())

for _ in range(Q):
    s, t = map(int, input().split())
    ans = D2[s-1][t-1]
    
    if ans==10**18:
        print(-1)
    else:
        print(ans-1) 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])
  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 d d N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L [10**18]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10**18]*N [10**18] 10**18 10 18 N D1 = [[10**18]*N for _ in range(N)] D1 [[10**18]*N for _ in range(N)] for i in range(N):
    D1[i][i] = 0
  i range(N) range N D1[i][i] = 0 D1[i][i] [i] D1 i i 0 for _ in range(M):
    A, B, C = map(int, input().split())
    D1[A-1][B-1] = C
    D1[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 D1[A-1][B-1] = C D1[A-1][B-1] [A-1] D1 A-1 A 1 B-1 B 1 C D1[B-1][A-1] = C D1[B-1][A-1] [B-1] D1 B-1 B 1 A-1 A 1 C warshall_floyd(D1) warshall_floyd D1 [10**18]*N for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) [10**18]*N [10**18] 10**18 10 18 N D2 = [[10**18]*N for _ in range(N)] D2 [[10**18]*N for _ in range(N)] for i in range(N):
    D2[i][i] = 0
     i range(N) range N D2[i][i] = 0 D2[i][i] [i] D2 i i 0 for i in range(N):
    for j in range(N):
        if i!=j and D1[i][j]<=L:
            D2[i][j] = 1 i range(N) range N for j in range(N):
        if i!=j and D1[i][j]<=L:
            D2[i][j] = 1 j range(N) range N if i!=j and D1[i][j]<=L:
            D2[i][j] = 1 i!=j and D1[i][j]<=L i!=j i j D1[i][j]<=L D1[i][j] [i] D1 i j L D2[i][j] = 1 D2[i][j] [i] D2 i j 1 warshall_floyd(D2) warshall_floyd D2 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    ans = D2[s-1][t-1]
    
    if ans==10**18:
        print(-1)
    else:
        print(ans-1) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t ans = D2[s-1][t-1] ans D2[s-1][t-1] [s-1] D2 s-1 s 1 t-1 t 1 if ans==10**18:
        print(-1)
    else:
        print(ans-1) ans==10**18 ans 10**18 10 18 print(-1) print -1 print(ans-1) print ans-1 ans 1 A, B, C = map(int, input().split()) map(int, input().split()) A ans = D2[s-1][t-1] D2[s-1][t-1] ans N, M, L = map(int, input().split()) map(int, input().split()) N C = map(int, input().split()) map(int, input().split()) C Q = int(input()) int(input()) Q B, C = map(int, input().split()) map(int, input().split()) B L = map(int, input().split()) map(int, input().split()) L D2 = [[10**18]*N for _ in range(N)] [[10**18]*N for _ in range(N)] D2 s, t = map(int, input().split()) map(int, input().split()) s t = map(int, input().split()) map(int, input().split()) t M, L = map(int, input().split()) map(int, input().split()) M 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])
  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])
  warshall_floyd D1 = [[10**18]*N for _ in range(N)] [[10**18]*N for _ in range(N)] D1
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])
 
N, M, L = map(int, input().split())
D1 = [[10**18]*N for _ in range(N)]
 
for i in range(N):
    D1[i][i] = 0
 
for _ in range(M):
    A, B, C = map(int, input().split())
    D1[A-1][B-1] = C
    D1[B-1][A-1] = C

warshall_floyd(D1)
D2 = [[10**18]*N for _ in range(N)]

for i in range(N):
    D2[i][i] = 0
    
for i in range(N):
    for j in range(N):
        if i!=j and D1[i][j]<=L:
            D2[i][j] = 1

warshall_floyd(D2)
Q = int(input())

for _ in range(Q):
    s, t = map(int, input().split())
    ans = D2[s-1][t-1]
    
    if ans==10**18:
        print(-1)
    else:
        print(ans-1)