$MAX_DAY = 3_652_425

def main
  n,q = gets.chomp.split(' ').map(&:to_i)
  days = Array.new($MAX_DAY + 1, 0)
  consum = []

  prev = 0
  n.times do
    w,t,x = gets.chomp.split(' ').map(&:to_i)
    prev.upto(days.size) do |i|
      if i == $MAX_DAY + 1
        puts 'Many years later'
        break
      end

      consum[i] = 0
      d = days[i] + (i == 0 ? 0 : consum[i-1])
      if d + i >= w
        puts i
        break if i == $MAX_DAY
        x.times do |j|
          break if (i + 1 + j) > $MAX_DAY
          days[i+1+j] += begin
            case t
            when 0; 1
            when 1; j+1
            when 2; (j+1) ** 2
            end
          end
        end
        prev = i
        break
      end
      consum[i] = d
    end
  end

  consum[prev] = days[prev] + consum[prev-1]
  last = 0
  (prev-1).upto(days.size) do |i|
    break if days[i] == 0
    consum[i] = days[i] + consum[i-1]
    last = i
  end

  q.times do
    target = gets.chomp.to_i
    if target <= last
      puts target + consum[target]
    else
      puts target + consum[-1]
    end
  end
end

main