N, M, L = gets.split.map(&:to_i)
ABCs = M.times.map{gets.split.map(&:to_i)}
Q = gets.to_i
STs = Q.times.map{gets.split.map(&:to_i)}
INF = 10**9

d = Array.new(N + 1){Array.new(N + 1, INF)}
ABCs.each do |a, b, c|
  d[a][b] = c
  d[b][a] = c
end
(1 .. N).each do |i|
  (1 .. N).each do |j|
    (1 .. N).each do |k|
      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 |i|
  (1 .. N).each do |j|
    (1 .. N).each do |k|
      d[i][j] = d[i][k] + d[k][j] if d[i][j] > d[i][k] + d[k][j]
    end
  end
end
STs.each do |s, t|
  puts d[s][t] == INF ? -1 : d[s][t] - 1
end