n,m,l = map(int, input().split())
wf=[[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c = list(map(int,input().split()))
    wf[a-1][b-1] = c
    wf[b-1][a-1] = c
q = int(input())
st=[list(map(int,input().split())) for i in range(q)]

from scipy.sparse.csgraph import floyd_warshall
for i in range(n):
    wf[i][i]=0
wf=floyd_warshall(wf)

for i in range(n):
    for j in range(n):
        if wf[i][j] <= l:
            wf[i][j] = 1
        else:
            wf[i][j] = float("inf")

wf=floyd_warshall(wf)

for que in st:
    s,t=que
    if wf[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(wf[s-1][t-1]-1)) n,m,l = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l [float("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) [float("inf") for i in range(n)] wf=[[float("inf") for i in range(n)] for j in range(n)] wf [[float("inf") for i in range(n)] for j in range(n)] for i in range(m):
    a,b,c = list(map(int,input().split()))
    wf[a-1][b-1] = c
    wf[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 wf[a-1][b-1] = c wf[a-1][b-1] [a-1] wf a-1 a 1 b-1 b 1 c wf[b-1][a-1] = c wf[b-1][a-1] [b-1] wf b-1 b 1 a-1 a 1 c q = int(input()) q int(input()) int input() input list(map(int,input().split())) for i in range(q) for i in range(q) i range(q) range q for i in range(q) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split st=[list(map(int,input().split())) for i in range(q)] st [list(map(int,input().split())) for i in range(q)] from scipy.sparse.csgraph import floyd_warshall for i in range(n):
    wf[i][i]=0 i range(n) range n wf[i][i]=0 wf[i][i] [i] wf i i 0 wf=floyd_warshall(wf) wf floyd_warshall(wf) floyd_warshall wf for i in range(n):
    for j in range(n):
        if wf[i][j] <= l:
            wf[i][j] = 1
        else:
            wf[i][j] = float("inf") i range(n) range n for j in range(n):
        if wf[i][j] <= l:
            wf[i][j] = 1
        else:
            wf[i][j] = float("inf") j range(n) range n if wf[i][j] <= l:
            wf[i][j] = 1
        else:
            wf[i][j] = float("inf") wf[i][j] <= l wf[i][j] [i] wf i j l wf[i][j] = 1 wf[i][j] [i] wf i j 1 wf[i][j] = float("inf") wf[i][j] [i] wf i j float("inf") float "inf" wf=floyd_warshall(wf) wf floyd_warshall(wf) floyd_warshall wf for que in st:
    s,t=que
    if wf[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(wf[s-1][t-1]-1)) que st s,t=que s que t if wf[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(wf[s-1][t-1]-1)) wf[s-1][t-1] == float("inf") wf[s-1][t-1] [s-1] wf s-1 s 1 t-1 t 1 float("inf") float "inf" print(-1) print -1 print(int(wf[s-1][t-1]-1)) print int(wf[s-1][t-1]-1) int wf[s-1][t-1]-1 wf[s-1][t-1] [s-1] wf s-1 s 1 t-1 t 1 1 wf=floyd_warshall(wf) floyd_warshall(wf) wf t=que que t wf=[[float("inf") for i in range(n)] for j in range(n)] [[float("inf") for i in range(n)] for j in range(n)] wf a,b,c = list(map(int,input().split())) list(map(int,input().split())) a s,t=que que s q = int(input()) int(input()) q n,m,l = map(int, input().split()) map(int, input().split()) n st=[list(map(int,input().split())) for i in range(q)] [list(map(int,input().split())) for i in range(q)] st m,l = map(int, input().split()) map(int, input().split()) m b,c = list(map(int,input().split())) list(map(int,input().split())) b wf=floyd_warshall(wf) floyd_warshall(wf) wf c = list(map(int,input().split())) list(map(int,input().split())) c l = map(int, input().split()) map(int, input().split()) l
n,m,l = map(int, input().split())
wf=[[float("inf") for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c = list(map(int,input().split()))
    wf[a-1][b-1] = c
    wf[b-1][a-1] = c
q = int(input())
st=[list(map(int,input().split())) for i in range(q)]

from scipy.sparse.csgraph import floyd_warshall
for i in range(n):
    wf[i][i]=0
wf=floyd_warshall(wf)

for i in range(n):
    for j in range(n):
        if wf[i][j] <= l:
            wf[i][j] = 1
        else:
            wf[i][j] = float("inf")

wf=floyd_warshall(wf)

for que in st:
    s,t=que
    if wf[s-1][t-1] == float("inf"):
        print(-1)
    else:
        print(int(wf[s-1][t-1]-1))