import sys
sys.setrecursionlimit(10 ** 9)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

INF = 10 ** 15

def warshall_floyd(dist, n):
    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])
    return dist

N, M, L = lr()
dist = [[INF] * (N+1) for _ in range(N+1)] # 1-indexed
for _ in range(M):
    a, b, c = lr()
    if c > L:
        continue
    dist[a][b] = c
    dist[b][a] = c

dist = warshall_floyd(dist, N+1)
supply = [[INF] * (N+1) for _ in range(N+1)] # 1-indexed 距離L以下で供給が1回必要
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if dist[i][j] <= L:
            supply[i][j] = supply[j][i] =  1

supply = warshall_floyd(supply, N+1)
Q = ir()
for _ in range(Q):
    s, t = lr()
    x = supply[s][t] - 1
    print(-1 if x + 1 == INF else x) import sys sys sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 sr = lambda: sys.stdin.readline().rstrip() sr lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ir = lambda: int(sr()) ir lambda: int(sr()) int(sr()) int sr() sr lr = lambda: list(map(int, sr().split())) lr lambda: list(map(int, sr().split())) list(map(int, sr().split())) list map(int, sr().split()) map int sr().split() ().split () sr split INF = 10 ** 15 INF 10 ** 15 10 15 def warshall_floyd(dist, n):
    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])
    return dist warshall_floyd 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 return dist dist dist dist n n N, M, L = lr() N lr() lr M L [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 dist = [[INF] * (N+1) for _ in range(N+1)] dist [[INF] * (N+1) for _ in range(N+1)] for _ in range(M):
    a, b, c = lr()
    if c > L:
        continue
    dist[a][b] = c
    dist[b][a] = c _ range(M) range M a, b, c = lr() a lr() lr b c if c > L:
        continue
     c > L c L continue dist[a][b] = c dist[a][b] [a] dist a b c dist[b][a] = c dist[b][a] [b] dist b a c dist = warshall_floyd(dist, N+1) dist warshall_floyd(dist, N+1) warshall_floyd dist N+1 N 1 [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 supply = [[INF] * (N+1) for _ in range(N+1)] supply [[INF] * (N+1) for _ in range(N+1)] for i in range(1, N+1):
    for j in range(i+1, N+1):
        if dist[i][j] <= L:
            supply[i][j] = supply[j][i] =  1 i range(1, N+1) range 1 N+1 N 1 for j in range(i+1, N+1):
        if dist[i][j] <= L:
            supply[i][j] = supply[j][i] =  1 j range(i+1, N+1) range i+1 i 1 N+1 N 1 if dist[i][j] <= L:
            supply[i][j] = supply[j][i] =  1 dist[i][j] <= L dist[i][j] [i] dist i j L supply[i][j] = supply[j][i] =  1 supply[i][j] [i] supply i j 1 = supply[j][i] =  1 supply[j][i] [j] supply j i 1 supply = warshall_floyd(supply, N+1) supply warshall_floyd(supply, N+1) warshall_floyd supply N+1 N 1 Q = ir() Q ir() ir for _ in range(Q):
    s, t = lr()
    x = supply[s][t] - 1
    print(-1 if x + 1 == INF else x) _ range(Q) range Q s, t = lr() s lr() lr t x = supply[s][t] - 1 x supply[s][t] - 1 supply[s][t] [s] supply s t 1 print(-1 if x + 1 == INF else x) print -1 if x + 1 == INF else x x + 1 == INF x + 1 x 1 INF -1 x lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr x = supply[s][t] - 1 supply[s][t] - 1 x dist = [[INF] * (N+1) for _ in range(N+1)] [[INF] * (N+1) for _ in range(N+1)] dist t = lr() lr() t sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr def warshall_floyd(dist, n):
    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])
    return dist def warshall_floyd(dist, n):
    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])
    return dist warshall_floyd N, M, L = lr() lr() N L = lr() lr() L M, L = lr() lr() M dist = warshall_floyd(dist, N+1) warshall_floyd(dist, N+1) dist INF = 10 ** 15 10 ** 15 INF supply = [[INF] * (N+1) for _ in range(N+1)] [[INF] * (N+1) for _ in range(N+1)] supply a, b, c = lr() lr() a Q = ir() ir() Q c = lr() lr() c b, c = lr() lr() b s, t = lr() lr() s supply = warshall_floyd(supply, N+1) warshall_floyd(supply, N+1) supply ir = lambda: int(sr()) lambda: int(sr()) ir
import sys
sys.setrecursionlimit(10 ** 9)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

INF = 10 ** 15

def warshall_floyd(dist, n):
    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])
    return dist

N, M, L = lr()
dist = [[INF] * (N+1) for _ in range(N+1)] # 1-indexed
for _ in range(M):
    a, b, c = lr()
    if c > L:
        continue
    dist[a][b] = c
    dist[b][a] = c

dist = warshall_floyd(dist, N+1)
supply = [[INF] * (N+1) for _ in range(N+1)] # 1-indexed 距離L以下で供給が1回必要
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if dist[i][j] <= L:
            supply[i][j] = supply[j][i] =  1

supply = warshall_floyd(supply, N+1)
Q = ir()
for _ in range(Q):
    s, t = lr()
    x = supply[s][t] - 1
    print(-1 if x + 1 == INF else x)
