n,m,l=map(int,input().split())

#基本的にワーシャルフロイドの場合、行列式のリストで距離を保管する
from scipy.sparse import csr_matrix
from scipy.sparse import csgraph 
d = [[10**12 for i in range(n+1)] for i in range(n+1)]
for i in range(m):
    x,y,z = map(int,input().split())
    #有向グラフか無向グラフかによってここで場合わけが生じる
    d[x][y] = z
    d[y][x] = z
    
for i in range(n+1):
    d[i][i] = 0 #自身のところに行くコストは０
q=int(input())
que=[]
for _ in range(q):
    s,t=map(int,input().split())
    que.append((s,t))
       
csr=csr_matrix(d)
K=csgraph.shortest_path(csr,method="FW",directed=True)
e = [[10**12 for i in range(n+1)] for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        if K[i][j]<=l:
            e[i][j]=1
            
for i in range(n+1):
    e[i][i]=0
    

A=csr_matrix(e)
ANS=csgraph.shortest_path(A,method="FW",directed=True)

for some in que:
    s,t=some[0],some[1]
    if int(ANS[s][t])<10**12:
        print(int(ANS[s][t])-1)
    else:
        print(-1)

 n,m,l=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l from scipy.sparse import csr_matrix from scipy.sparse import csgraph [10**12 for i in range(n+1)] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [10**12 for i in range(n+1)] d = [[10**12 for i in range(n+1)] for i in range(n+1)] d [[10**12 for i in range(n+1)] for i in range(n+1)] for i in range(m):
    x,y,z = map(int,input().split())
    #有向グラフか無向グラフかによってここで場合わけが生じる
    d[x][y] = z
    d[y][x] = z
     i range(m) range m x,y,z = map(int,input().split()) x map(int,input().split()) map int input().split() ().split () input split y z d[x][y] = z d[x][y] [x] d x y z d[y][x] = z d[y][x] [y] d y x z for i in range(n+1):
    d[i][i] = 0 #自身のところに行くコストは０ i range(n+1) range n+1 n 1 d[i][i] = 0 d[i][i] [i] d i i 0 q=int(input()) q int(input()) int input() input que=[] que [] for _ in range(q):
    s,t=map(int,input().split())
    que.append((s,t))
        _ range(q) range q s,t=map(int,input().split()) s map(int,input().split()) map int input().split() ().split () input split t que.append((s,t)) que.append que append (s,t) s t csr=csr_matrix(d) csr csr_matrix(d) csr_matrix d K=csgraph.shortest_path(csr,method="FW",directed=True) K csgraph.shortest_path(csr,method="FW",directed=True) csgraph.shortest_path csgraph shortest_path csr method="FW" method "FW" directed=True directed True [10**12 for i in range(n+1)] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [10**12 for i in range(n+1)] e = [[10**12 for i in range(n+1)] for i in range(n+1)] e [[10**12 for i in range(n+1)] for i in range(n+1)] for i in range(1,n+1):
    for j in range(1,n+1):
        if K[i][j]<=l:
            e[i][j]=1
             i range(1,n+1) range 1 n+1 n 1 for j in range(1,n+1):
        if K[i][j]<=l:
            e[i][j]=1
             j range(1,n+1) range 1 n+1 n 1 if K[i][j]<=l:
            e[i][j]=1
             K[i][j]<=l K[i][j] [i] K i j l e[i][j]=1 e[i][j] [i] e i j 1 for i in range(n+1):
    e[i][i]=0
     i range(n+1) range n+1 n 1 e[i][i]=0 e[i][i] [i] e i i 0 A=csr_matrix(e) A csr_matrix(e) csr_matrix e ANS=csgraph.shortest_path(A,method="FW",directed=True) ANS csgraph.shortest_path(A,method="FW",directed=True) csgraph.shortest_path csgraph shortest_path A method="FW" method "FW" directed=True directed True for some in que:
    s,t=some[0],some[1]
    if int(ANS[s][t])<10**12:
        print(int(ANS[s][t])-1)
    else:
        print(-1) some que s,t=some[0],some[1] s some[0] some 0 t some[1] some 1 if int(ANS[s][t])<10**12:
        print(int(ANS[s][t])-1)
    else:
        print(-1) int(ANS[s][t])<10**12 int(ANS[s][t]) int ANS[s][t] [s] ANS s t 10**12 10 12 print(int(ANS[s][t])-1) print int(ANS[s][t])-1 int(ANS[s][t]) int ANS[s][t] [s] ANS s t 1 print(-1) print -1 s,t=map(int,input().split()) map(int,input().split()) s s,t=some[0],some[1] some[0] s m,l=map(int,input().split()) map(int,input().split()) m ANS=csgraph.shortest_path(A,method="FW",directed=True) csgraph.shortest_path(A,method="FW",directed=True) ANS l=map(int,input().split()) map(int,input().split()) l que=[] [] que t=some[0],some[1] some[1] t K=csgraph.shortest_path(csr,method="FW",directed=True) csgraph.shortest_path(csr,method="FW",directed=True) K e = [[10**12 for i in range(n+1)] for i in range(n+1)] [[10**12 for i in range(n+1)] for i in range(n+1)] e y,z = map(int,input().split()) map(int,input().split()) y z = map(int,input().split()) map(int,input().split()) z A=csr_matrix(e) csr_matrix(e) A csr=csr_matrix(d) csr_matrix(d) csr t=map(int,input().split()) map(int,input().split()) t n,m,l=map(int,input().split()) map(int,input().split()) n x,y,z = map(int,input().split()) map(int,input().split()) x d = [[10**12 for i in range(n+1)] for i in range(n+1)] [[10**12 for i in range(n+1)] for i in range(n+1)] d q=int(input()) int(input()) q
n,m,l=map(int,input().split())

#基本的にワーシャルフロイドの場合、行列式のリストで距離を保管する
from scipy.sparse import csr_matrix
from scipy.sparse import csgraph 
d = [[10**12 for i in range(n+1)] for i in range(n+1)]
for i in range(m):
    x,y,z = map(int,input().split())
    #有向グラフか無向グラフかによってここで場合わけが生じる
    d[x][y] = z
    d[y][x] = z
    
for i in range(n+1):
    d[i][i] = 0 #自身のところに行くコストは０
q=int(input())
que=[]
for _ in range(q):
    s,t=map(int,input().split())
    que.append((s,t))
       
csr=csr_matrix(d)
K=csgraph.shortest_path(csr,method="FW",directed=True)
e = [[10**12 for i in range(n+1)] for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,n+1):
        if K[i][j]<=l:
            e[i][j]=1
            
for i in range(n+1):
    e[i][i]=0
    

A=csr_matrix(e)
ANS=csgraph.shortest_path(A,method="FW",directed=True)

for some in que:
    s,t=some[0],some[1]
    if int(ANS[s][t])<10**12:
        print(int(ANS[s][t])-1)
    else:
        print(-1)


