N, M, L = gets.to_s.split.map{|t|t.to_i}
d = Array.new(301){ [L+1] * 301 }

M.times do
  a, b, c = gets.to_s.split.map{|t|t.to_i}
  d[a][b] = d[b][a] = c
end

1.upto(N) do |k|
  1.upto(N) do |i|
    1.upto(N) do |j|
      d[i][j] = d[i][k] + d[k][j] if d[i][j] > d[i][k] + d[k][j]
    end
  end
end

1.upto(N) do |i|
  1.upto(N) do |j|
    d[i][j] = 1 if d[i][j] <= L
  end
end

1.upto(N) do |k|
  1.upto(N) do |i|
    1.upto(N) do |j|
      d[i][j] = d[i][k] + d[k][j] if d[i][j] > d[i][k] + d[k][j]
    end
  end
end

ans = []
q = gets.to_s.to_i
q.times do
  s, t = gets.to_s.split.map{|t|t.to_i}
  ans << (d[s][t] > L ? -1 : d[s][t] - 1)
end

puts ans