N,M,L = gets.split.map &:to_i
A,B,C = Array.new(M){gets.split.map &:to_i}.transpose
Q = gets.to_i
S,T = Array.new(Q){gets.split.map &:to_i}.transpose


INF = 10**9 + 1
G = Array.new(N){Array.new(N,INF)}

N.times do |n|
    G[n][n] = 0
end

# p [N,M,L,A,B,C,Q,S,T]
# p [M,A,B,C]
M.times do |m|
    G[A[m]-1][B[m]-1] = C[m]
    G[B[m]-1][A[m]-1] = C[m]
end


N.times do |k|
    N.times do |i|
        N.times do |j|
            a = G[i][j]
            b = G[i][k] + G[k][j]
            G[i][j] = a < b ? a : b
        end
    end
end

H = Array.new(N){Array.new(N,INF)}
N.times do |n|
    H[n][n] = 0
end
N.times do |i|
    N.times do |j|
        H[i][j] = 1 if G[i][j] <= L
    end
end
N.times do |k|
    N.times do |i|
        N.times do |j|
            a = H[i][j]
            b = H[i][k] + H[k][j]
            H[i][j] = a < b ? a : b
        end
    end
end

Q.times do |q|
    count = H[S[q]-1][T[q]-1]-1
    puts count >= INF - 1 ? -1 : count
end