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)
  @d[a][b] = @d[b][a] = c
end

def wf
  (1 .. N).each do |k|
    (1 ... k).each do |j|
      (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
    (k + 1 .. N).each do |j|
      (1 ... k).each 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
end

wf
(1 .. N).each do |j|
  (1 ... j).each do |i|
    @d[i][j] = @d[i][j] <= L ? 1 : L + 1
  end
end
wf
gets.to_i.times do
  s, t = gets.split.map(&:to_i)
  s, t = t, s if s > t
  puts @d[s][t] > L ? -1 : @d[s][t] - 1
end