N, M, L = gets.split.map(&:to_i)
d = Array.new(N + 1){Array.new(N + 1, L + 1)}
M.times do
  a, b, c = gets.split.map(&:to_i)
  d[a][b] = d[b][a] = c
end
(1 .. N).each do |k|
  (1 .. N).each do |i|
    (1 .. N).each 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 .. N).each do |i|
  (1 .. N).each do |j|
    d[i][j] = 1 if d[i][j] <= L
  end
end
(1 .. N).each do |k|
  (1 .. N).each do |i|
    (1 .. N).each do |j|
      d[i][j] = d[i][k] + d[k][j] if d[i][j] > d[i][k] + d[k][j]
    end
  end
end
gets.to_i.times do
  s, t = gets.split.map(&:to_i)
  puts d[s][t] > L ? -1 : d[s][t] - 1
end