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

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

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

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

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

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

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

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

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