from sys import setrecursionlimit as SRL, stdin
inf = 10**15
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

n, m, l = rrd()
dis = [[inf] * 305 for _i in range(305)]
need = [[inf] * 305 for _i in range(305)]
for i in range(n):
    dis[i][i] = 0
for i in range(m):
    a, b, c = rrd()
    dis[a][b] = c
    dis[b][a] = c

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

for i in range(1, n + 1):
    for j in range(1, n + 1):
        if i == j:
            need[i][j] = 0
        elif dis[i][j] <= l:
            need[i][j] = 1

for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            need[i][j] = min(need[i][j], need[i][k] + need[k][j])
q = int(input())

while q:
    s, t = rrd()
    if need[s][t] < inf:
        print(need[s][t]-1)
    else:
        print(-1)
    q -= 1







 from sys import setrecursionlimit as SRL, stdin inf = 10**15 inf 10**15 10 15 SRL(10 ** 7) SRL 10 ** 7 10 7 rd = stdin.readline rd stdin.readline stdin readline rrd = lambda: map(int, rd().strip().split()) rrd lambda: map(int, rd().strip().split()) map(int, rd().strip().split()) map int rd().strip().split() ().strip().split ().strip() ().strip () rd strip split n, m, l = rrd() n rrd() rrd m l [inf] * 305 for _i in range(305) for _i in range(305) _i range(305) range 305 for _i in range(305) [inf] * 305 [inf] inf 305 dis = [[inf] * 305 for _i in range(305)] dis [[inf] * 305 for _i in range(305)] [inf] * 305 for _i in range(305) for _i in range(305) _i range(305) range 305 for _i in range(305) [inf] * 305 [inf] inf 305 need = [[inf] * 305 for _i in range(305)] need [[inf] * 305 for _i in range(305)] for i in range(n):
    dis[i][i] = 0 i range(n) range n dis[i][i] = 0 dis[i][i] [i] dis i i 0 for i in range(m):
    a, b, c = rrd()
    dis[a][b] = c
    dis[b][a] = c i range(m) range m a, b, c = rrd() a rrd() rrd b c 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(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]) k range(1, n + 1) range 1 n + 1 n 1 for i in range(1, n + 1):
        for j in range(1, n + 1):
            dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]) i range(1, n + 1) range 1 n + 1 n 1 for j in range(1, n + 1):
            dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]) j range(1, n + 1) range 1 n + 1 n 1 dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]) dis[i][j] [i] dis i j min(dis[i][j], dis[i][k] + dis[k][j]) min dis[i][j] [i] dis i j dis[i][k] + dis[k][j] dis[i][k] [i] dis i k dis[k][j] [k] dis k j for i in range(1, n + 1):
    for j in range(1, n + 1):
        if i == j:
            need[i][j] = 0
        elif dis[i][j] <= l:
            need[i][j] = 1 i range(1, n + 1) range 1 n + 1 n 1 for j in range(1, n + 1):
        if i == j:
            need[i][j] = 0
        elif dis[i][j] <= l:
            need[i][j] = 1 j range(1, n + 1) range 1 n + 1 n 1 if i == j:
            need[i][j] = 0
        elif dis[i][j] <= l:
            need[i][j] = 1 i == j i j need[i][j] = 0 need[i][j] [i] need i j 0 elif dis[i][j] <= l:
            need[i][j] = 1 dis[i][j] <= l dis[i][j] [i] dis i j l need[i][j] = 1 need[i][j] [i] need i j 1 for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            need[i][j] = min(need[i][j], need[i][k] + need[k][j]) k range(1, n + 1) range 1 n + 1 n 1 for i in range(1, n + 1):
        for j in range(1, n + 1):
            need[i][j] = min(need[i][j], need[i][k] + need[k][j]) i range(1, n + 1) range 1 n + 1 n 1 for j in range(1, n + 1):
            need[i][j] = min(need[i][j], need[i][k] + need[k][j]) j range(1, n + 1) range 1 n + 1 n 1 need[i][j] = min(need[i][j], need[i][k] + need[k][j]) need[i][j] [i] need i j min(need[i][j], need[i][k] + need[k][j]) min need[i][j] [i] need i j need[i][k] + need[k][j] need[i][k] [i] need i k need[k][j] [k] need k j q = int(input()) q int(input()) int input() input while q:
    s, t = rrd()
    if need[s][t] < inf:
        print(need[s][t]-1)
    else:
        print(-1)
    q -= 1 q s, t = rrd() s rrd() rrd t if need[s][t] < inf:
        print(need[s][t]-1)
    else:
        print(-1)
     need[s][t] < inf need[s][t] [s] need s t inf print(need[s][t]-1) print need[s][t]-1 need[s][t] [s] need s t 1 print(-1) print -1 q -= 1 q 1 rrd = lambda: map(int, rd().strip().split()) lambda: map(int, rd().strip().split()) rrd n, m, l = rrd() rrd() n q -= 1 1 q b, c = rrd() rrd() b c = rrd() rrd() c s, t = rrd() rrd() s t = rrd() rrd() t need = [[inf] * 305 for _i in range(305)] [[inf] * 305 for _i in range(305)] need l = rrd() rrd() l rd = stdin.readline stdin.readline rd m, l = rrd() rrd() m dis = [[inf] * 305 for _i in range(305)] [[inf] * 305 for _i in range(305)] dis a, b, c = rrd() rrd() a q = int(input()) int(input()) q inf = 10**15 10**15 inf
from sys import setrecursionlimit as SRL, stdin
inf = 10**15
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())

n, m, l = rrd()
dis = [[inf] * 305 for _i in range(305)]
need = [[inf] * 305 for _i in range(305)]
for i in range(n):
    dis[i][i] = 0
for i in range(m):
    a, b, c = rrd()
    dis[a][b] = c
    dis[b][a] = c

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

for i in range(1, n + 1):
    for j in range(1, n + 1):
        if i == j:
            need[i][j] = 0
        elif dis[i][j] <= l:
            need[i][j] = 1

for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            need[i][j] = min(need[i][j], need[i][k] + need[k][j])
q = int(input())

while q:
    s, t = rrd()
    if need[s][t] < inf:
        print(need[s][t]-1)
    else:
        print(-1)
    q -= 1








