import sys
input = sys.stdin.readline
#道がない場合、infで初期化したい
inf = 10 ** 13 + 1
#input
n, m, l = list(map(int, input().split()))
way = [[inf for i in range(n)] for j in range(n)]
oil = [[400 for i in range(n)] for j in range(n)]

for i in range(m):
    a, b, c, = list(map(int, input().split()))
    way[a - 1][b - 1] = c
    way[b - 1][a - 1] = c

q = int(input())

query = []

for i in range(q):
    query.append(list(map(int, input().split())))

#ワーシャルフロイド法を使い、各道への最短経路を調べる。計算量はO(N**3)
for k in range(n):
    for i in range(n):
        for j in range(n):
            if i == j:
                way[i][j] = 0
                continue
            way[i][j] = min(way[i][j],way[i][k] + way[k][j])
            
#oilの補給できる回数もワーシャルフロイドで求める。まず、一補給でいけるところに辺を張る
for i in range(n):
    for j in range(n):
        if i == j:
            oil[i][j] = 0
        if way[i][j] <= l:
            oil[i][j] = oil[j][i] = 1
#の後でワーシャルフロイド
for k in range(n):
    for i in range(n):
        for j in range(n):
            if i == j:
                oil[i][j] = 0
                continue
            oil[i][j] = min(oil[i][j],oil[i][k] + oil[k][j])

for i in range(q):
    ans = oil[query[i][0] - 1][query[i][1] - 1] - 1
    if way[query[i][0] - 1][query[i][1] - 1] == inf or oil[query[i][0] - 1][query[i][1] - 1] == 400:
        ans = -1
    print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline inf = 10 ** 13 + 1 inf 10 ** 13 + 1 10 ** 13 10 13 1 n, m, l = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m l [inf for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [inf for i in range(n)] way = [[inf for i in range(n)] for j in range(n)] way [[inf for i in range(n)] for j in range(n)] [400 for i in range(n)] for j in range(n) for j in range(n) j range(n) range n for j in range(n) [400 for i in range(n)] oil = [[400 for i in range(n)] for j in range(n)] oil [[400 for i in range(n)] for j in range(n)] for i in range(m):
    a, b, c, = list(map(int, input().split()))
    way[a - 1][b - 1] = c
    way[b - 1][a - 1] = c i range(m) range m a, b, c, = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b c way[a - 1][b - 1] = c way[a - 1][b - 1] [a - 1] way a - 1 a 1 b - 1 b 1 c way[b - 1][a - 1] = c way[b - 1][a - 1] [b - 1] way b - 1 b 1 a - 1 a 1 c q = int(input()) q int(input()) int input() input query = [] query [] for i in range(q):
    query.append(list(map(int, input().split())))

#ワーシャルフロイド法を使い、各道への最短経路を調べる。計算量はO(N**3) i range(q) range q query.append(list(map(int, input().split()))) query.append query append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for k in range(n):
    for i in range(n):
        for j in range(n):
            if i == j:
                way[i][j] = 0
                continue
            way[i][j] = min(way[i][j],way[i][k] + way[k][j])
            
#oilの補給できる回数もワーシャルフロイドで求める。まず、一補給でいけるところに辺を張る k range(n) range n for i in range(n):
        for j in range(n):
            if i == j:
                way[i][j] = 0
                continue
            way[i][j] = min(way[i][j],way[i][k] + way[k][j])
            
#oilの補給できる回数もワーシャルフロイドで求める。まず、一補給でいけるところに辺を張る i range(n) range n for j in range(n):
            if i == j:
                way[i][j] = 0
                continue
            way[i][j] = min(way[i][j],way[i][k] + way[k][j])
            
#oilの補給できる回数もワーシャルフロイドで求める。まず、一補給でいけるところに辺を張る j range(n) range n if i == j:
                way[i][j] = 0
                continue
             i == j i j way[i][j] = 0 way[i][j] [i] way i j 0 continue way[i][j] = min(way[i][j],way[i][k] + way[k][j]) way[i][j] [i] way i j min(way[i][j],way[i][k] + way[k][j]) min way[i][j] [i] way i j way[i][k] + way[k][j] way[i][k] [i] way i k way[k][j] [k] way k j for i in range(n):
    for j in range(n):
        if i == j:
            oil[i][j] = 0
        if way[i][j] <= l:
            oil[i][j] = oil[j][i] = 1
#の後でワーシャルフロイド i range(n) range n for j in range(n):
        if i == j:
            oil[i][j] = 0
        if way[i][j] <= l:
            oil[i][j] = oil[j][i] = 1
#の後でワーシャルフロイド j range(n) range n if i == j:
            oil[i][j] = 0
         i == j i j oil[i][j] = 0 oil[i][j] [i] oil i j 0 if way[i][j] <= l:
            oil[i][j] = oil[j][i] = 1
#の後でワーシャルフロイド way[i][j] <= l way[i][j] [i] way i j l oil[i][j] = oil[j][i] = 1 oil[i][j] [i] oil i j 1 = oil[j][i] = 1 oil[j][i] [j] oil j i 1 for k in range(n):
    for i in range(n):
        for j in range(n):
            if i == j:
                oil[i][j] = 0
                continue
            oil[i][j] = min(oil[i][j],oil[i][k] + oil[k][j]) k range(n) range n for i in range(n):
        for j in range(n):
            if i == j:
                oil[i][j] = 0
                continue
            oil[i][j] = min(oil[i][j],oil[i][k] + oil[k][j]) i range(n) range n for j in range(n):
            if i == j:
                oil[i][j] = 0
                continue
            oil[i][j] = min(oil[i][j],oil[i][k] + oil[k][j]) j range(n) range n if i == j:
                oil[i][j] = 0
                continue
             i == j i j oil[i][j] = 0 oil[i][j] [i] oil i j 0 continue oil[i][j] = min(oil[i][j],oil[i][k] + oil[k][j]) oil[i][j] [i] oil i j min(oil[i][j],oil[i][k] + oil[k][j]) min oil[i][j] [i] oil i j oil[i][k] + oil[k][j] oil[i][k] [i] oil i k oil[k][j] [k] oil k j for i in range(q):
    ans = oil[query[i][0] - 1][query[i][1] - 1] - 1
    if way[query[i][0] - 1][query[i][1] - 1] == inf or oil[query[i][0] - 1][query[i][1] - 1] == 400:
        ans = -1
    print(ans) i range(q) range q ans = oil[query[i][0] - 1][query[i][1] - 1] - 1 ans oil[query[i][0] - 1][query[i][1] - 1] - 1 oil[query[i][0] - 1][query[i][1] - 1] [query[i][0] - 1] oil query[i][0] - 1 query[i][0] [i] query i 0 1 query[i][1] - 1 query[i][1] [i] query i 1 1 1 if way[query[i][0] - 1][query[i][1] - 1] == inf or oil[query[i][0] - 1][query[i][1] - 1] == 400:
        ans = -1
     way[query[i][0] - 1][query[i][1] - 1] == inf or oil[query[i][0] - 1][query[i][1] - 1] == 400 way[query[i][0] - 1][query[i][1] - 1] == inf way[query[i][0] - 1][query[i][1] - 1] [query[i][0] - 1] way query[i][0] - 1 query[i][0] [i] query i 0 1 query[i][1] - 1 query[i][1] [i] query i 1 1 inf oil[query[i][0] - 1][query[i][1] - 1] == 400 oil[query[i][0] - 1][query[i][1] - 1] [query[i][0] - 1] oil query[i][0] - 1 query[i][0] [i] query i 0 1 query[i][1] - 1 query[i][1] [i] query i 1 1 400 ans = -1 ans -1 print(ans) print ans b, c, = list(map(int, input().split())) list(map(int, input().split())) b way = [[inf for i in range(n)] for j in range(n)] [[inf for i in range(n)] for j in range(n)] way n, m, l = list(map(int, input().split())) list(map(int, input().split())) n m, l = list(map(int, input().split())) list(map(int, input().split())) m ans = oil[query[i][0] - 1][query[i][1] - 1] - 1 oil[query[i][0] - 1][query[i][1] - 1] - 1 ans oil = [[400 for i in range(n)] for j in range(n)] [[400 for i in range(n)] for j in range(n)] oil q = int(input()) int(input()) q l = list(map(int, input().split())) list(map(int, input().split())) l inf = 10 ** 13 + 1 10 ** 13 + 1 inf input = sys.stdin.readline sys.stdin.readline input query = [] [] query c, = list(map(int, input().split())) list(map(int, input().split())) c a, b, c, = list(map(int, input().split())) list(map(int, input().split())) a ans = -1 -1 ans
import sys
input = sys.stdin.readline
#道がない場合、infで初期化したい
inf = 10 ** 13 + 1
#input
n, m, l = list(map(int, input().split()))
way = [[inf for i in range(n)] for j in range(n)]
oil = [[400 for i in range(n)] for j in range(n)]

for i in range(m):
    a, b, c, = list(map(int, input().split()))
    way[a - 1][b - 1] = c
    way[b - 1][a - 1] = c

q = int(input())

query = []

for i in range(q):
    query.append(list(map(int, input().split())))

#ワーシャルフロイド法を使い、各道への最短経路を調べる。計算量はO(N**3)
for k in range(n):
    for i in range(n):
        for j in range(n):
            if i == j:
                way[i][j] = 0
                continue
            way[i][j] = min(way[i][j],way[i][k] + way[k][j])
            
#oilの補給できる回数もワーシャルフロイドで求める。まず、一補給でいけるところに辺を張る
for i in range(n):
    for j in range(n):
        if i == j:
            oil[i][j] = 0
        if way[i][j] <= l:
            oil[i][j] = oil[j][i] = 1
#の後でワーシャルフロイド
for k in range(n):
    for i in range(n):
        for j in range(n):
            if i == j:
                oil[i][j] = 0
                continue
            oil[i][j] = min(oil[i][j],oil[i][k] + oil[k][j])

for i in range(q):
    ans = oil[query[i][0] - 1][query[i][1] - 1] - 1
    if way[query[i][0] - 1][query[i][1] - 1] == inf or oil[query[i][0] - 1][query[i][1] - 1] == 400:
        ans = -1
    print(ans)
