import sys

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

N, M, L = lr()
INF = 10 ** 19
dis = [[INF for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    a, b, c = lr()
    if c > L:
        continue
    dis[a][b] = c
    dis[b][a] = c

for k in range(N+1): # kが中継地点
    for i in range(N+1):
        for j in range(i+1, N+1):
            x = dis[i][k] + dis[k][j]
            if x < dis[i][j]:
                dis[i][j] = dis[j][i] = x

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

for k in range(N+1): # kが中継地点
    for i in range(N+1):
        for j in range(i+1, N+1):
            y = supply[i][k] + supply[k][j]
            if y < supply[i][j]:
                supply[i][j] = supply[j][i] = y

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

# 59  import sys sys 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 N, M, L = lr() N lr() lr M L INF = 10 ** 19 INF 10 ** 19 10 19 [INF for _ in range(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 for _ in range(N+1)] dis = [[INF for _ in range(N+1)] for _ in range(N+1)] dis [[INF for _ in range(N+1)] for _ in range(N+1)] for _ in range(M):
    a, b, c = lr()
    if c > L:
        continue
    dis[a][b] = c
    dis[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 dis[a][b] = c dis[a][b] [a] dis a b c dis[b][a] = c dis[b][a] [b] dis b a c for k in range(N+1): # kが中継地点
    for i in range(N+1):
        for j in range(i+1, N+1):
            x = dis[i][k] + dis[k][j]
            if x < dis[i][j]:
                dis[i][j] = dis[j][i] = x k range(N+1) range N+1 N 1 for i in range(N+1):
        for j in range(i+1, N+1):
            x = dis[i][k] + dis[k][j]
            if x < dis[i][j]:
                dis[i][j] = dis[j][i] = x i range(N+1) range N+1 N 1 for j in range(i+1, N+1):
            x = dis[i][k] + dis[k][j]
            if x < dis[i][j]:
                dis[i][j] = dis[j][i] = x j range(i+1, N+1) range i+1 i 1 N+1 N 1 x = dis[i][k] + dis[k][j] x dis[i][k] + dis[k][j] dis[i][k] [i] dis i k dis[k][j] [k] dis k j if x < dis[i][j]:
                dis[i][j] = dis[j][i] = x x < dis[i][j] x dis[i][j] [i] dis i j dis[i][j] = dis[j][i] = x dis[i][j] [i] dis i j x = dis[j][i] = x dis[j][i] [j] dis j i x [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(N+1):
    for j in range(i+1, N+1):
        if dis[i][j] <= L:
            supply[i][j] = supply[j][i] = 1 i range(N+1) range N+1 N 1 for j in range(i+1, N+1):
        if dis[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 dis[i][j] <= L:
            supply[i][j] = supply[j][i] = 1 dis[i][j] <= L dis[i][j] [i] dis 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 for k in range(N+1): # kが中継地点
    for i in range(N+1):
        for j in range(i+1, N+1):
            y = supply[i][k] + supply[k][j]
            if y < supply[i][j]:
                supply[i][j] = supply[j][i] = y k range(N+1) range N+1 N 1 for i in range(N+1):
        for j in range(i+1, N+1):
            y = supply[i][k] + supply[k][j]
            if y < supply[i][j]:
                supply[i][j] = supply[j][i] = y i range(N+1) range N+1 N 1 for j in range(i+1, N+1):
            y = supply[i][k] + supply[k][j]
            if y < supply[i][j]:
                supply[i][j] = supply[j][i] = y j range(i+1, N+1) range i+1 i 1 N+1 N 1 y = supply[i][k] + supply[k][j] y supply[i][k] + supply[k][j] supply[i][k] [i] supply i k supply[k][j] [k] supply k j if y < supply[i][j]:
                supply[i][j] = supply[j][i] = y y < supply[i][j] y supply[i][j] [i] supply i j supply[i][j] = supply[j][i] = y supply[i][j] [i] supply i j y = supply[j][i] = y supply[j][i] [j] supply j i y Q = ir() Q ir() ir for _ in range(Q):
    s, t = lr()
    if supply[s][t] == INF:
        print(-1)
    else:
        print(supply[s][t] - 1)

# 59  _ range(Q) range Q s, t = lr() s lr() lr t if supply[s][t] == INF:
        print(-1)
    else:
        print(supply[s][t] - 1)

# 59  supply[s][t] == INF supply[s][t] [s] supply s t INF print(-1) print -1 print(supply[s][t] - 1) print supply[s][t] - 1 supply[s][t] [s] supply s t 1 ir = lambda: int(sr()) lambda: int(sr()) ir Q = ir() ir() Q x = dis[i][k] + dis[k][j] dis[i][k] + dis[k][j] x lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr a, b, c = lr() lr() a sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr dis = [[INF for _ in range(N+1)] for _ in range(N+1)] [[INF for _ in range(N+1)] for _ in range(N+1)] dis s, t = lr() lr() s L = lr() lr() L c = lr() lr() c INF = 10 ** 19 10 ** 19 INF y = supply[i][k] + supply[k][j] supply[i][k] + supply[k][j] y N, M, L = lr() lr() N b, c = lr() lr() b M, L = lr() lr() M supply = [[INF] * (N+1) for _ in range(N+1)] [[INF] * (N+1) for _ in range(N+1)] supply t = lr() lr() t
import sys

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

N, M, L = lr()
INF = 10 ** 19
dis = [[INF for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    a, b, c = lr()
    if c > L:
        continue
    dis[a][b] = c
    dis[b][a] = c

for k in range(N+1): # kが中継地点
    for i in range(N+1):
        for j in range(i+1, N+1):
            x = dis[i][k] + dis[k][j]
            if x < dis[i][j]:
                dis[i][j] = dis[j][i] = x

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

for k in range(N+1): # kが中継地点
    for i in range(N+1):
        for j in range(i+1, N+1):
            y = supply[i][k] + supply[k][j]
            if y < supply[i][j]:
                supply[i][j] = supply[j][i] = y

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

# 59 