INF = 10**20

def warsahll_floyd(distances)
  size = N + 1
  size.times do |i|
    size.times do |j|
      size.times do |k|
        distances[i][j] = [distances[i][j], distances[i][k] + distances[k][j]].min
      end
    end
  end
  distances
end

N, M, L = gets.chomp.split.map(&:to_i)

distances = Array.new(N + 1) { Array.new(N + 1, INF) }
1.upto(N) { |i| distances[i][i] = 0 }
M.times do
  a, b, c = gets.chomp.split.map(&:to_i)
  next if c > L
  distances[a][b] = c
  distances[b][a] = c
end

Q = gets.chomp.to_i
queries = []
Q.times { queries << gets.chomp.split.map(&:to_i) }

distances = warsahll_floyd(distances)
distances.map! do |array|
  array.map do |d|
    if d > L
      INF
    else
      1
    end
  end
end

distances = warsahll_floyd(distances)
distances.map! do |array|
  array.map do |d|
    d == INF ? -1 : d - 1
  end
end

queries.each do |query|
  puts distances[query[0]][query[1]]
end
