def min(a,b); a < b ? a : b; end

N, M, L = gets.split.map(&:to_i)
cost = Array.new(N + 1){ Array.new(N + 1, -1) }
dp = Array.new(N + 1){ Array.new(N + 1, -1) }

(1 .. N).each{|i| cost[i][i] = dp[i][i] = 0 }
M.times do
  a,b,c = gets.split.map(&:to_i)
  cost[a][b] = cost[b][a] = c
end

(1 .. N).each do |i|
  (1 .. N).each do |j|
    (1 .. N).each do |k|
      next if cost[i][k] < 0 || cost[k][j] < 0
      if cost[i][j] < 0
        cost[i][j] = cost[i][k] + cost[k][j]
      else
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
      end
    end
  end
end

(1 .. N).each do |i|
  (1 .. N).each do |j|
    dp[i][j] = dp[j][i] = 1 if cost[i][j] <= L && cost[i][j] >= 0
  end
end

(1 .. N).each do |i|
  (1 .. N).each do |j|
    (1 .. N).each do |k|
      next if dp[i][k] < 0 || dp[k][j] < 0
      if dp[i][j] < 0
        dp[i][j] = dp[i][k] + dp[k][j]
      else
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
      end
    end
  end
end

Q = gets.to_i
ANS = Q.times.map do
  s,t = gets.split.map(&:to_i)
  dp[s][t] > 0 ? dp[s][t] - 1 : dp[s][t]
end
puts ANS
