
def warshall_floyd(g)
  n = g.length
  ret = Array.new(n).map {Array.new(n)}
  
  n.times do |i|
    ret[i][i] = 0
    g[i].each {|j, c| ret[i][j] = c}
  end
  
  (0...n).each do |k|
    (0...n).each do |i|
      (0...n).each do |j|
        if !ret[i][k].nil? and !ret[k][j].nil?
          if ret[i][j].nil?
            ret[i][j] = ret[i][k] + ret[k][j]
          else
            ret[i][j] = [ret[i][j], ret[i][k] + ret[k][j]].min
          end
        end
      end
    end 
  end
  
  ret
end

n, m, l = STDIN.gets.split.map(&:to_i)

g = Array.new(n).map {Array.new}

m.times do
  a, b, c = STDIN.gets.split.map(&:to_i)
  
  if c <= l
    g[a-1] << [b-1, c]
    g[b-1] << [a-1, c]
  end
end

w = warshall_floyd(g)

g2 = Array.new(n).map {Array.new}
n.times do |i|
  n.times do |j|
    if !w[i][j].nil? and w[i][j] <= l
      g2[i] << [j, 1]
    end
  end
end

w2 = warshall_floyd(g2)

q = STDIN.gets.to_i

q.times do
  s, t = STDIN.gets.split.map(&:to_i)

  if w2[s-1][t-1].nil?
    puts -1
  else
    puts w2[s-1][t-1] - 1
  end
end
