N, M, L = gets.split.map(&:to_i)
d = Array.new(301*301, L + 1)

M.times do
  a, b, c = gets.split.map(&:to_i)
  d[a+b*301] = d[b+a*301] = c
end

(1 .. N).each do |k|
  (1 .. N).each do |i|
    (1 .. N).each do |j|
      d[i+j*301] = d[i+k*301] + d[k+j*301] if d[i+j*301] > d[i+k*301] + d[k+j*301]
    end
  end
end
(1 .. N).each do |i|
  (1 .. N).each do |j|
    d[i+j*301] = 1 if d[i+j*301] <= L
  end
end
(1 .. N).each do |k|
  (1 .. N).each do |i|
    (1 .. N).each do |j|
      d[i+j*301] = d[i+k*301] + d[k+j*301] if d[i+j*301] > d[i+k*301] + d[k+j*301]
    end
  end
end
gets.to_i.times do
  s, t = gets.split.map(&:to_i)
  puts d[s+t*301] > L ? -1 : d[s+t*301] - 1
end