N, M, L = gets.split.map(&:to_i)
dist1 = Array.new(N) { Array.new(N, 1_000_000_001) }
dist2 = Array.new(N) { Array.new(N, 1_000_000_001) }

N.times do |i|
  dist1[i][i] = dist2[i][i] = 0
end

M.times do
  a_b_c = gets.chomp.split.map { |s| s.to_i - 1}
  dist1[a_b_c[0]][a_b_c[1]] = dist1[a_b_c[1]][a_b_c[0]] = a_b_c[2] + 1
end

N.times do |i|
  N.times do |j|
    N.times do |k|
      next if j == k
      if dist1[j][k] > dist1[j][i] + dist1[i][k]
        dist1[j][k] = dist1[k][j] = dist1[j][i] + dist1[i][k]
      end
    end
  end
end

N.times do |i|
  N.times do |j|
    next if i == j
    dist2[i][j] = dist2[j][i] = 1 if dist1[i][j] <= L
  end
end

N.times do |i|
  N.times do |j|
    N.times do |k|
      next if j == k
      if dist2[j][k] > dist2[j][i] + dist2[i][k]
        dist2[j][k] = dist2[k][j] = dist2[j][i] + dist2[i][k]
      end
    end
  end
end

Q = gets.chomp.to_i
Q.times do
  s,t = gets.chomp.split.map { |s| s.to_i - 1}
  puts dist2[s][t] == 1_000_000_001 ? -1 : dist2[s][t] - 1
end