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

# n.times{|i| d[i][j] == 0 }

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

1.upto(N) do |i|
  1.upto(N) do |j|
    d[i][j] = 1 if d[i][j] <= L || i == j
  end
end

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

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

puts ans