n, m, l = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
query = [list(map(int, input().split())) for _ in range(q)]

INF = 1001001001
dist = [[INF for _ in range(n)] for _ in range(n)]
for i in range(n):
    dist[i][i] = 0

for road in ls:
    dist[road[0]-1][road[1]-1] = dist[road[1]-1][road[0]-1] = road[2]

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])

dist2 = [[INF for _ in range(n)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            dist2[i][j] = 1

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

for el in query:
    ans = dist2[el[0]-1][el[1]-1]-1
    if dist2[el[0]-1][el[1]-1] == INF:
        ans = -1
    print(ans) n, m, l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ls = [list(map(int, input().split())) for _ in range(m)] ls [list(map(int, input().split())) for _ in range(m)] q = int(input()) q int(input()) int input() input list(map(int, input().split())) for _ in range(q) for _ in range(q) _ range(q) range q for _ in range(q) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split query = [list(map(int, input().split())) for _ in range(q)] query [list(map(int, input().split())) for _ in range(q)] INF = 1001001001 INF 1001001001 [INF for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF for _ in range(n)] dist = [[INF for _ in range(n)] for _ in range(n)] dist [[INF for _ in range(n)] for _ in range(n)] for i in range(n):
    dist[i][i] = 0 i range(n) range n dist[i][i] = 0 dist[i][i] [i] dist i i 0 for road in ls:
    dist[road[0]-1][road[1]-1] = dist[road[1]-1][road[0]-1] = road[2] road ls dist[road[0]-1][road[1]-1] = dist[road[1]-1][road[0]-1] = road[2] dist[road[0]-1][road[1]-1] [road[0]-1] dist road[0]-1 road[0] road 0 1 road[1]-1 road[1] road 1 1 road[2] road 2 = dist[road[1]-1][road[0]-1] = road[2] dist[road[1]-1][road[0]-1] [road[1]-1] dist road[1]-1 road[1] road 1 1 road[0]-1 road[0] road 0 1 road[2] 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 [INF for _ in range(n)] for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [INF for _ in range(n)] dist2 = [[INF for _ in range(n)] for _ in range(n)] dist2 [[INF for _ in range(n)] for _ in range(n)] for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            dist2[i][j] = 1 i range(n) range n for j in range(n):
        if dist[i][j] <= l:
            dist2[i][j] = 1 j range(n) range n if dist[i][j] <= l:
            dist2[i][j] = 1 dist[i][j] <= l dist[i][j] [i] dist i j l dist2[i][j] = 1 dist2[i][j] [i] dist2 i j 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) i range(n) range n for j in range(n):
            dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) j range(n) range n dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]) dist2[i][j] [i] dist2 i j min(dist2[i][j], dist2[i][k] + dist2[k][j]) min dist2[i][j] [i] dist2 i j dist2[i][k] + dist2[k][j] dist2[i][k] [i] dist2 i k dist2[k][j] [k] dist2 k j for el in query:
    ans = dist2[el[0]-1][el[1]-1]-1
    if dist2[el[0]-1][el[1]-1] == INF:
        ans = -1
    print(ans) el query ans = dist2[el[0]-1][el[1]-1]-1 ans dist2[el[0]-1][el[1]-1]-1 dist2[el[0]-1][el[1]-1] [el[0]-1] dist2 el[0]-1 el[0] el 0 1 el[1]-1 el[1] el 1 1 1 if dist2[el[0]-1][el[1]-1] == INF:
        ans = -1
     dist2[el[0]-1][el[1]-1] == INF dist2[el[0]-1][el[1]-1] [el[0]-1] dist2 el[0]-1 el[0] el 0 1 el[1]-1 el[1] el 1 1 INF ans = -1 ans -1 print(ans) print ans l = map(int, input().split()) map(int, input().split()) l m, l = map(int, input().split()) map(int, input().split()) m dist2 = [[INF for _ in range(n)] for _ in range(n)] [[INF for _ in range(n)] for _ in range(n)] dist2 ls = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] ls ans = dist2[el[0]-1][el[1]-1]-1 dist2[el[0]-1][el[1]-1]-1 ans INF = 1001001001 1001001001 INF q = int(input()) int(input()) q ans = -1 -1 ans n, m, l = map(int, input().split()) map(int, input().split()) n dist = [[INF for _ in range(n)] for _ in range(n)] [[INF for _ in range(n)] for _ in range(n)] dist query = [list(map(int, input().split())) for _ in range(q)] [list(map(int, input().split())) for _ in range(q)] query
n, m, l = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
q = int(input())
query = [list(map(int, input().split())) for _ in range(q)]

INF = 1001001001
dist = [[INF for _ in range(n)] for _ in range(n)]
for i in range(n):
    dist[i][i] = 0

for road in ls:
    dist[road[0]-1][road[1]-1] = dist[road[1]-1][road[0]-1] = road[2]

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])

dist2 = [[INF for _ in range(n)] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if dist[i][j] <= l:
            dist2[i][j] = 1

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

for el in query:
    ans = dist2[el[0]-1][el[1]-1]-1
    if dist2[el[0]-1][el[1]-1] == INF:
        ans = -1
    print(ans)