n = gets.to_i
frases = []
n.times do
  s, t, u = gets.split.map(&:to_i)
  (s..t).each do |i|
    frases << [i, u]
  end
end
m = gets.to_i
melodies = []
maxm = 0
m.times do
  t = gets.to_i
  melodies << t
  maxm = t if maxm < t
end

dp = Array.new(maxm + 1, -1)
dp[0] = 0
frases.each_with_index do |v, j|
  v[0].upto(maxm) do |i|
    if dp[i - v[0]] != -1 && dp[i] < dp[i - v[0]] + v[1]
      dp[i] = dp[i - v[0]] + v[1]
    end
  end
end

ans = []
melodies.each do |melody|
  if dp[melody] != -1
    ans << dp[melody]
  else
    puts -1
    exit
  end
end
ans.each do |a|
  puts a
end
