def pp(o)
#  STDERR.puts o.inspect
end
def min(a, b)
 (a > b) ? a : b
end


n,m,l = gets.chomp.split(' ').map(&:to_i)

route = Array.new(n+1){Array.new(n+1, l*2)} # 距離
route2 = Array.new(n+1){Array.new(n+1, l*2)}  # 無補給移動可能マップ
route3 = Array.new(n+1){Array.new(n+1, 0)}  # 補給回数

m.times do
  from, to, len = gets.chomp.split(' ').map(&:to_i)
  route[from][to] = len
  route[to][from] = len
end

pp "距離"
pp route
nodes_size = route.size
nodes_size.times do |k|
  nodes_size.times do |i|
    nodes_size.times do |j|
      route[i][j] = min(route[i][j], route[i][k] + route[k][j])
    end
  end
end

nodes_size.times do |i|
  nodes_size.times do |j|
    if route[i][j] <= l then
      route2[i][j] = 1
    end
  end
end
pp "無補給移動可能マップ"
pp route2


nodes_size.times do |k|
  nodes_size.times do |i|
    nodes_size.times do |j|
      route2[i][j] = min(route2[i][j], route2[i][k] + route2[k][j])
    end
  end
end
pp "補給数"
pp route2

q= gets.chomp.to_i
q.times do
  s, t = gets.chomp.split(' ').map(&:to_i)
  if route2[s][t] < l then
    print "#{route2[s][t]-1}\n"
  else
    print "-1\n"
  end
end

