Path = Struct.new(:from, :to, :cost)
Town = Struct.new(:index, :cost, :from, :fixed, :cost_from_last_town)

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

paths = m.times.map {
  Path.new(*gets.split(' ').map(&:to_i))
}.select { |path|
  path.cost <= l
}

def shortest_path(from, to, paths, towns)
  loop do
    unfixed_towns = towns.reject(&:fixed)
    break if unfixed_towns.empty?
    
    fixed_town = unfixed_towns.min_by(&:cost)
    fixed_town.fixed = true

    paths.each do |path|
      next if path.from != fixed_town.index && path.to != fixed_town.index

      dest_town = towns[path.from == fixed_town.index ? path.to : path.from]
      new_cost = fixed_town.cost + path.cost
      if new_cost < dest_town.cost
        dest_town.cost = new_cost
        dest_town.from = fixed_town.index
        dest_town.cost_from_last_town = path.cost
      end
    end
  end

  return nil if towns[to].cost == Float::INFINITY

  route = [towns[to]]
  loop do
    from = route.first.from
    break if from.nil?

    route.unshift(towns[from])
  end
  route
end

q = gets.to_i
q.times do
  s, t = gets.split(' ').map(&:to_i)

  towns = (n + 1).times.map { |index| Town.new(index, Float::INFINITY, nil, false) }
  towns[s].cost = 0

  route = shortest_path(s, t, paths, towns)

  if route.nil?
    puts -1
    next
  end

  remain = l
  answer = 0

  route.drop(1).each do |town|
    remain -= town.cost_from_last_town

    if remain < 0
      remain += l
      answer += 1
    end
  end

  puts answer
end
