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**12

d = Array.new(N){Array.new(N, INF)}
ABCs.each do |a, b, c|
  a -= 1; b -= 1
  d[a][b] = d[b][a] = c
end
[*0 ... N].permutation(3).each do |i, j, k|
  d[i][j] = d[i][k] + d[k][j] if d[i][j] > d[i][k] + d[k][j]
end
x = Array.new(N){Array.new(N, INF)}
[*0 ... N].permutation(2).each do |i, j|
  x[i][j] = 1 if d[i][j] <= L
end
[*0 ... N].permutation(3).each do |i, j, k|
  x[i][j] = x[i][k] + x[k][j] if x[i][j] > x[i][k] + x[k][j]
end
STs.each do |s, t|
  s -= 1; t -= 1
  puts x[s][t] == INF ? -1 : x[s][t] - 1
end