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){|i| d[i][i] = 0 }


1.upto(N) do |k|
  1.upto(k) do |i|
    t = d[i][k]
    # next if t >= L || i == k
    1.upto(i+1) do |j|
      tt = t + d[k][j]
      d[i][j] = tt if d[i][j] > tt
    end
  end
  (k-1).upto(N) do |i|
    t = d[k][i]
    # next if t >= L || i == k
    0.upto(k) do |j|
      tt = t + d[j][k]
      d[j][i] = tt if d[i][j] > tt
    end
    (k-1).upto(i+1) do |j|
      tt = t + d[k][j]
      d[i][j] = tt if d[i][j] > tt
    end
  end
end

all_ok = true

1.upto(N) do |i|
  1.upto(N) do |j|
    d[i][j] <= L ? (d[i][j] = 1) : (all_ok = false) 
  end
end

q = gets.to_s.to_i
# all_ok = true
if all_ok
  puts [0] * q
  exit
end

1.upto(N) do |k|
  1.upto(N) do |i|
    t = d[i][k]
    next if t >= L || i == k
    1.upto(N) do |j|
      tt = t + d[k][j]
      d[i][j] = tt if d[i][j] > tt
    end
  end
end
# ans = []

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

puts ans
