N, M, L = map(int, input().split())

INF = 10 ** 18
lst1 = [[INF] * (N + 1) for _ in range(N+1)] #頂点1に隣接する辺以外の道の管理
# u-->vへコストlで行ける時
for i in range(N+1):
    lst1[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    lst1[a][b] = c
    lst1[b][a] = c

# 処理する部分
def WarshallFloyd(lst):
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
    return
# i-->jのコストはlst[i][j]

WarshallFloyd(lst1)

lst2 = [[INF] * (N + 1) for _ in range(N + 1)]
for i in range(N):
    lst2[i][i] = 0
    for j in range(i + 1, N + 1):
        if lst1[i][j] <= L:
            lst2[i][j] = 1
            lst2[j][i] = 1

WarshallFloyd(lst2)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    if lst2[s][t] >= INF:
        print (-1)
    else:
        print (max(lst2[s][t] - 1, 0)) N, M, L = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M L INF = 10 ** 18 INF 10 ** 18 10 18 [INF] * (N + 1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [INF] * (N + 1) [INF] INF N + 1 N 1 lst1 = [[INF] * (N + 1) for _ in range(N+1)] lst1 [[INF] * (N + 1) for _ in range(N+1)] for i in range(N+1):
    lst1[i][i] = 0 i range(N+1) range N+1 N 1 lst1[i][i] = 0 lst1[i][i] [i] lst1 i i 0 for _ in range(M):
    a, b, c = map(int, input().split())
    lst1[a][b] = c
    lst1[b][a] = 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 lst1[a][b] = c lst1[a][b] [a] lst1 a b c lst1[b][a] = c lst1[b][a] [b] lst1 b a c def WarshallFloyd(lst):
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
    return
# i-->jのコストはlst[i][j] WarshallFloyd for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
     k range(N+1) range N+1 N 1 for i in range(N+1):
            for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
     i range(N+1) range N+1 N 1 for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
     j range(N+1) range N+1 N 1 lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j]) lst[i][j] [i] lst i j min(lst[i][j], lst[i][k] + lst[k][j]) min lst[i][j] [i] lst i j lst[i][k] + lst[k][j] lst[i][k] [i] lst i k lst[k][j] [k] lst k j return lst lst WarshallFloyd(lst1) WarshallFloyd lst1 [INF] * (N + 1) for _ in range(N + 1) for _ in range(N + 1) _ range(N + 1) range N + 1 N 1 for _ in range(N + 1) [INF] * (N + 1) [INF] INF N + 1 N 1 lst2 = [[INF] * (N + 1) for _ in range(N + 1)] lst2 [[INF] * (N + 1) for _ in range(N + 1)] for i in range(N):
    lst2[i][i] = 0
    for j in range(i + 1, N + 1):
        if lst1[i][j] <= L:
            lst2[i][j] = 1
            lst2[j][i] = 1 i range(N) range N lst2[i][i] = 0 lst2[i][i] [i] lst2 i i 0 for j in range(i + 1, N + 1):
        if lst1[i][j] <= L:
            lst2[i][j] = 1
            lst2[j][i] = 1 j range(i + 1, N + 1) range i + 1 i 1 N + 1 N 1 if lst1[i][j] <= L:
            lst2[i][j] = 1
            lst2[j][i] = 1 lst1[i][j] <= L lst1[i][j] [i] lst1 i j L lst2[i][j] = 1 lst2[i][j] [i] lst2 i j 1 lst2[j][i] = 1 lst2[j][i] [j] lst2 j i 1 WarshallFloyd(lst2) WarshallFloyd lst2 Q = int(input()) Q int(input()) int input() input for _ in range(Q):
    s, t = map(int, input().split())
    if lst2[s][t] >= INF:
        print (-1)
    else:
        print (max(lst2[s][t] - 1, 0)) _ range(Q) range Q s, t = map(int, input().split()) s map(int, input().split()) map int input().split() ().split () input split t if lst2[s][t] >= INF:
        print (-1)
    else:
        print (max(lst2[s][t] - 1, 0)) lst2[s][t] >= INF lst2[s][t] [s] lst2 s t INF print (-1) print -1 print (max(lst2[s][t] - 1, 0)) print max(lst2[s][t] - 1, 0) max lst2[s][t] - 1 lst2[s][t] [s] lst2 s t 1 0 t = map(int, input().split()) map(int, input().split()) t b, c = map(int, input().split()) map(int, input().split()) b s, t = map(int, input().split()) map(int, input().split()) s N, M, L = map(int, input().split()) map(int, input().split()) N Q = int(input()) int(input()) Q lst1 = [[INF] * (N + 1) for _ in range(N+1)] [[INF] * (N + 1) for _ in range(N+1)] lst1 def WarshallFloyd(lst):
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
    return
# i-->jのコストはlst[i][j] def WarshallFloyd(lst):
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
    return
# i-->jのコストはlst[i][j] WarshallFloyd lst2 = [[INF] * (N + 1) for _ in range(N + 1)] [[INF] * (N + 1) for _ in range(N + 1)] lst2 M, L = map(int, input().split()) map(int, input().split()) M a, b, c = map(int, input().split()) map(int, input().split()) a L = map(int, input().split()) map(int, input().split()) L c = map(int, input().split()) map(int, input().split()) c INF = 10 ** 18 10 ** 18 INF
N, M, L = map(int, input().split())

INF = 10 ** 18
lst1 = [[INF] * (N + 1) for _ in range(N+1)] #頂点1に隣接する辺以外の道の管理
# u-->vへコストlで行ける時
for i in range(N+1):
    lst1[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    lst1[a][b] = c
    lst1[b][a] = c

# 処理する部分
def WarshallFloyd(lst):
    for k in range(N+1):
        for i in range(N+1):
            for j in range(N+1):
                lst[i][j] = min(lst[i][j], lst[i][k] + lst[k][j])
    return
# i-->jのコストはlst[i][j]

WarshallFloyd(lst1)

lst2 = [[INF] * (N + 1) for _ in range(N + 1)]
for i in range(N):
    lst2[i][i] = 0
    for j in range(i + 1, N + 1):
        if lst1[i][j] <= L:
            lst2[i][j] = 1
            lst2[j][i] = 1

WarshallFloyd(lst2)

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