INF = 10**9
N, M, L = gets.split.map(&:to_i)
@d = Array.new(N + 1){Array.new(N + 1, L + 1)}
M.times do
  a, b, c = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  @d[a][b] = @d[b][a] = c
end
N.times do |k|
  k.times do |j|
    j.times do |i|
      @d[i][j] = @d[i][k] + @d[k][j] if @d[i][j] > @d[i][k] + @d[k][j]
    end
  end
  (k + 1 ... N).each do |j|
    k.times do |i|
      @d[i][j] = @d[i][k] + @d[k][j] if @d[i][j] > @d[i][k] + @d[k][j]
    end
    (k + 1 ... j).each do |i|
      @d[i][j] = @d[i][k] + @d[k][j] if @d[i][j] > @d[i][k] + @d[k][j]
    end
  end
end
N.times do |j|
  j.times do |i|
    @d[i][j] = @d[i][j] <= L ? 1 : INF
  end
end
N.times do |k|
  k.times do |j|
    j.times do |i|
      @d[i][j] = @d[i][k] + @d[k][j] if @d[i][j] > @d[i][k] + @d[k][j]
    end
  end
  (k + 1 ... N).each do |j|
    k.times do |i|
      @d[i][j] = @d[i][k] + @d[k][j] if @d[i][j] > @d[i][k] + @d[k][j]
    end
    (k + 1 ... j).each do |i|
      @d[i][j] = @d[i][k] + @d[k][j] if @d[i][j] > @d[i][k] + @d[k][j]
    end
  end
end
readlines.drop(1).map{|l| l.split.map(&:to_i)}.each do |s, t|
  s -= 1
  t -= 1
  s, t = t, s if s > t
  puts @d[s][t] < INF ? @d[s][t] - 1 : -1
end