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