import sys
input = sys.stdin.readline
N, m, l = map(int, input().split())
graph = [[] for i in range(N+1)]

INF = 2 ** 31 - 1
d = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
    d[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    d[a][b] = c
    d[b][a] = c


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

d2 = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
    d[i][i] = 0

for i in range(N+1):
    for j in range(N+1):
        if d[i][j] <= l:
            d2[i][j] = 1

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


q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    if d2[s][t] == INF:
        print(-1)
    else:
        print(d2[s][t] - 1) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, m, l = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split m l [] for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [] graph = [[] for i in range(N+1)] graph [[] for i in range(N+1)] INF = 2 ** 31 - 1 INF 2 ** 31 - 1 2 ** 31 2 31 1 [INF for i in range(N+1)] for j in range(N+1) for j in range(N+1) j range(N+1) range N+1 N 1 for j in range(N+1) [INF for i in range(N+1)] d = [[INF for i in range(N+1)] for j in range(N+1)] d [[INF for i in range(N+1)] for j in range(N+1)] for i in range(N+1):
    d[i][i] = 0 i range(N+1) range N+1 N 1 d[i][i] = 0 d[i][i] [i] d i i 0 for i in range(m):
    a, b, c = map(int, input().split())
    d[a][b] = c
    d[b][a] = c i 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][b] = c d[a][b] [a] d a b c d[b][a] = c d[b][a] [b] d b a c for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) k range(N+1) range N+1 N 1 for i in range(N+1):
        for j in range(N+1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) i range(N+1) range N+1 N 1 for j in range(N+1):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]) j range(N+1) range N+1 N 1 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 [INF for i in range(N+1)] for j in range(N+1) for j in range(N+1) j range(N+1) range N+1 N 1 for j in range(N+1) [INF for i in range(N+1)] d2 = [[INF for i in range(N+1)] for j in range(N+1)] d2 [[INF for i in range(N+1)] for j in range(N+1)] for i in range(N+1):
    d[i][i] = 0 i range(N+1) range N+1 N 1 d[i][i] = 0 d[i][i] [i] d i i 0 for i in range(N+1):
    for j in range(N+1):
        if d[i][j] <= l:
            d2[i][j] = 1 i range(N+1) range N+1 N 1 for j in range(N+1):
        if d[i][j] <= l:
            d2[i][j] = 1 j range(N+1) range N+1 N 1 if d[i][j] <= l:
            d2[i][j] = 1 d[i][j] <= l d[i][j] [i] d i j l d2[i][j] = 1 d2[i][j] [i] d2 i j 1 for k in range(N+1):
    for i in range(N+1):
        for j in range(N+1):
            d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]) k range(N+1) range N+1 N 1 for i in range(N+1):
        for j in range(N+1):
            d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]) i range(N+1) range N+1 N 1 for j in range(N+1):
            d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]) j range(N+1) range N+1 N 1 d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]) d2[i][j] [i] d2 i j min(d2[i][j], d2[i][k] + d2[k][j]) min d2[i][j] [i] d2 i j d2[i][k] + d2[k][j] d2[i][k] [i] d2 i k d2[k][j] [k] d2 k j q = int(input()) q int(input()) int input() input for i in range(q):
    s, t = map(int, input().split())
    if d2[s][t] == INF:
        print(-1)
    else:
        print(d2[s][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 if d2[s][t] == INF:
        print(-1)
    else:
        print(d2[s][t] - 1) d2[s][t] == INF d2[s][t] [s] d2 s t INF print(-1) print -1 print(d2[s][t] - 1) print d2[s][t] - 1 d2[s][t] [s] d2 s t 1 q = int(input()) int(input()) q m, l = map(int, input().split()) map(int, input().split()) m input = sys.stdin.readline sys.stdin.readline input N, m, l = map(int, input().split()) map(int, input().split()) N INF = 2 ** 31 - 1 2 ** 31 - 1 INF c = map(int, input().split()) map(int, input().split()) c b, c = map(int, input().split()) map(int, input().split()) b d2 = [[INF for i in range(N+1)] for j in range(N+1)] [[INF for i in range(N+1)] for j in range(N+1)] d2 a, b, c = map(int, input().split()) map(int, input().split()) a l = map(int, input().split()) map(int, input().split()) l t = map(int, input().split()) map(int, input().split()) t s, t = map(int, input().split()) map(int, input().split()) s graph = [[] for i in range(N+1)] [[] for i in range(N+1)] graph d = [[INF for i in range(N+1)] for j in range(N+1)] [[INF for i in range(N+1)] for j in range(N+1)] d
import sys
input = sys.stdin.readline
N, m, l = map(int, input().split())
graph = [[] for i in range(N+1)]

INF = 2 ** 31 - 1
d = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
    d[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    d[a][b] = c
    d[b][a] = c


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

d2 = [[INF for i in range(N+1)] for j in range(N+1)]
for i in range(N+1):
    d[i][i] = 0

for i in range(N+1):
    for j in range(N+1):
        if d[i][j] <= l:
            d2[i][j] = 1

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


q = int(input())
for i in range(q):
    s, t = map(int, input().split())
    if d2[s][t] == INF:
        print(-1)
    else:
        print(d2[s][t] - 1)
