import scala.collection.mutable

object Main extends App {
  import scala.io.StdIn._

  class State {
    var lastServiceChanged = ActualTime(0)
    var earnedBonusUntilLastServiceChanged = Progression(0)
    val additionalBonus = Bonus()
    def progressionAt(day: ActualTime): Progression = earnedBonusUntilLastServiceChanged + additionalBonus.bonusBetween(lastServiceChanged, day + 1) + day.toDayProgression
    def progressionAfter(day: ActualTime): Progression = progressionAt(lastServiceChanged + day.day)
    def addServiceBonus(serviceBonus: ServiceBonus): Unit = {
      val add = additionalBonus.bonusBetween(lastServiceChanged, serviceBonus.startTime)
      earnedBonusUntilLastServiceChanged += add
      lastServiceChanged = serviceBonus.startTime
      additionalBonus.add(serviceBonus)
    }
    def removeServiceBonus(serviceBonus: ServiceBonus): Unit = {
      val add = additionalBonus.bonusBetween(lastServiceChanged, serviceBonus.endTime)
      assert(add.progress >= 0)
      earnedBonusUntilLastServiceChanged += add
      lastServiceChanged = serviceBonus.endTime
      additionalBonus.remove(serviceBonus)
    }
  }
  val state = new State()
  val timeLimit = 3652426
  val Array(n, q) = readLine.trim.split(' ').map(_.toInt)
  val services: Array[Service] = Array.tabulate(n){i ⇒
    val Array(w, t, x) = readLine.trim.split(' ').map(_.toLong)
    new Service(i, w, t, x)
  }
  val actualTimeAtRecovery = Array.tabulate(services.length){ _ ⇒ ActualTime(0)}
  val queries = Array.tabulate(q){i ⇒
    Query(ActualTime(readLong), i)
  }
  val progressionAtQuery: Array[Progression] = Array.tabulate(queries.length){_ ⇒ Progression(0)}
  val eventsWithProgression = mutable.PriorityQueue()(Ordering.by[Service, BigInt](_.recoveryProgression.progress).reverse).also(_.enqueue(services:_*))
  val eventsWithActualTime = mutable.PriorityQueue()(Ordering.by[Event, BigInt](_.time.day).reverse).also(_.enqueue(queries:_*))
  while(eventsWithActualTime.nonEmpty || eventsWithProgression.nonEmpty){
    if (eventsWithActualTime.nonEmpty && (eventsWithProgression.isEmpty || eventsWithProgression.head.recoveryProgression.progress > state.progressionAt(eventsWithActualTime.head.time).progress)) {//イベントを進める
      eventsWithActualTime.dequeue() match {
        case Query(time, id) ⇒
          progressionAtQuery(id) = state.progressionAt(time)
        case BonusEnd(t, service) ⇒
          state.removeServiceBonus(service)
      }
    }else {//サービスを復旧
      val service = eventsWithProgression.dequeue()
      val recoveryTime = ActualTime(lowerBound(state.lastServiceChanged.day, timeLimit, service.recoveryProgression.progress))
      actualTimeAtRecovery(service.id) = recoveryTime
      val bonus = service.recoveryAt(recoveryTime)
      state.addServiceBonus(bonus)
      eventsWithActualTime.enqueue(BonusEnd(bonus.endTime, bonus))
    }

  }
  def lowerBound(from: BigInt, to: BigInt, target: BigInt): BigInt = {
    var left = from
    var right = to
    while(left < right){
      val mid = (left + right) / 2
      if (state.progressionAt(ActualTime(mid)).progress < target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  if (actualTimeAtRecovery.nonEmpty) println(actualTimeAtRecovery.map(a ⇒ if (a.day >= timeLimit) "Many years later" else a.day.toString).mkString("\n"))
  println(progressionAtQuery.map(i ⇒ i.progress).mkString("\n"))
  case class ActualTime(day: BigInt) extends AnyVal {
    def +(that: BigInt): ActualTime = ActualTime(day + that)
    def -(that: ActualTime): ActualTime = ActualTime(day - that.day)
    def toDayProgression: Progression = Progression(day)
  }
  case class Progression(progress: BigInt) extends AnyVal {
    def +(that: Progression): Progression = Progression(progress + that.progress)
    def -(that: Progression): Progression = Progression(progress - that.progress)
  }
  sealed trait Event {
    def time: ActualTime
  }
  case class BonusEnd(time: ActualTime, service: ServiceBonus) extends Event
  case class Query(time: ActualTime, id: Int) extends Event
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
  case class Bonus(var type0: Type0AdditionalBonus = Type0AdditionalBonus(), var type1: Type1AdditionalBonus = Type1AdditionalBonus(), var type2: Type2AdditionalBonus = Type2AdditionalBonus()) {
    def addBonus(type0Bonus: Type0Bonus): Unit = type0 = type0.addService(type0Bonus)
    def addBonus(type1Bonus: Type1Bonus): Unit = type1 = type1.addService(type1Bonus)
    def addBonus(type2Bonus: Type2Bonus): Unit = type2 = type2.addService(type2Bonus)
    def add(bonus: ServiceBonus): Unit = bonus match {
      case b: Type0Bonus ⇒ addBonus(b)
      case b: Type1Bonus ⇒ addBonus(b)
      case b: Type2Bonus ⇒ addBonus(b)
    }
    def removeBonus(type0Bonus: Type0Bonus): Unit = type0 = type0.removeService(type0Bonus)
    def removeBonus(type1Bonus: Type1Bonus): Unit = type1 = type1.removeService(type1Bonus)
    def removeBonus(type2Bonus: Type2Bonus): Unit = type2 = type2.removeService(type2Bonus)
    def remove(bonus: ServiceBonus): Unit = bonus match {
      case b: Type0Bonus ⇒ removeBonus(b)
      case b: Type1Bonus ⇒ removeBonus(b)
      case b: Type2Bonus ⇒ removeBonus(b)
    }
    def bonusBetween(from: ActualTime, until: ActualTime): Progression = {//from until until のイベントが処理済み
      type0.bonusBetween(from, until) + type1.bonusBetween(from, until) + type2.bonusBetween(from, until)
    }
  }
  class Service(val id: Int, w: Long, t: Long, x: Long) {
    def recoveryProgression: Progression = Progression(w)
    def recoveryAt(time: ActualTime): ServiceBonus = t match {
      case 0 ⇒ Type0Bonus(time, x.toInt)
      case 1 ⇒ Type1Bonus(time, x.toInt)
      case 2 ⇒ Type2Bonus(time, x.toInt)
      case _ ⇒ ???
    }
  }
  sealed trait ServiceBonus {
    def x: Int
    def startTime: ActualTime
    def endTime: ActualTime = ActualTime(startTime.day + x)
  }
  case class Type0Bonus(startTime: ActualTime, x: Int) extends ServiceBonus
  case class Type1Bonus(startTime: ActualTime, x: Int) extends ServiceBonus
  case class Type2Bonus(startTime: ActualTime, x: Int) extends ServiceBonus
  trait AdditionalBonus {//epochDay => epochBonus それ以外の日は計算で求める
    protected def bonusAt(day: ActualTime): Progression = bonusBetween(day, day + 1)
    protected def baseBonusAt(day: ActualTime): Progression = baseBonusFromEpoch(day + 1) - baseBonusFromEpoch(day)
    protected def baseBonusFromEpoch(until: ActualTime): Progression
    protected def serviceCount: Int
    protected def epochBonus: Progression
    protected def epochDay: ActualTime
    def bonusBetween(from: ActualTime, until: ActualTime): Progression = if (from == until) Progression(0) else if (from == epochDay) epochBonus + baseBonusFromEpoch(until) - baseBonusFromEpoch(from + 1) else baseBonusFromEpoch(until) - baseBonusFromEpoch(from)
  }
  case class Type0AdditionalBonus(override val serviceCount: Int = 0, override val epochDay: ActualTime = ActualTime(0), override val epochBonus: Progression = Progression(0)) extends AdditionalBonus {
    override protected def baseBonusFromEpoch(until: ActualTime): Progression = Progression(serviceCount * (until - epochDay).day)
    def addService(serviceBonus: Type0Bonus): Type0AdditionalBonus = Type0AdditionalBonus(serviceCount + 1, serviceBonus.startTime, bonusAt(serviceBonus.startTime))
    def removeService(serviceBonus: Type0Bonus): Type0AdditionalBonus = Type0AdditionalBonus(serviceCount - 1, serviceBonus.endTime, bonusAt(serviceBonus.endTime))
  }
  case class Type1AdditionalBonus(override val serviceCount: Int = 0, override val epochDay: ActualTime = ActualTime(0), override val epochBonus: Progression = Progression(0), baseBonus: Progression = Progression(0)) extends AdditionalBonus {
    override protected def baseBonusFromEpoch(until: ActualTime): Progression = (until - epochDay).day.let(t ⇒ Progression(baseBonus.progress * t + t * (t - 1) / 2 * serviceCount))
    def addService(serviceBonus: Type1Bonus): Type1AdditionalBonus = Type1AdditionalBonus(serviceCount + 1, serviceBonus.startTime, bonusAt(serviceBonus.startTime), baseBonusAt(serviceBonus.startTime))
    def removeService(serviceBonus: Type1Bonus): Type1AdditionalBonus = Type1AdditionalBonus(serviceCount - 1, serviceBonus.endTime, bonusAt(serviceBonus.endTime), baseBonusAt(serviceBonus.endTime) - (serviceBonus.endTime - serviceBonus.startTime).toDayProgression)
  }
  case class Type2AdditionalBonus(override val serviceCount: Int = 0, override val epochDay: ActualTime = ActualTime(0), override val epochBonus: Progression = Progression(0), baseBonus: Progression = Progression(0), sumDays: BigInt = 0) extends AdditionalBonus {
    override protected def baseBonusFromEpoch(until: ActualTime): Progression = (until - epochDay).day.let(t ⇒ Progression(baseBonus.progress * t + t * (t - 1) / 2 * (2 * sumDays - serviceCount) + serviceCount * t * (t - 1) * (2 * t - 1) / 6 + serviceCount * t * (t - 1) / 2))
    def addService(serviceBonus: Type2Bonus): Type2AdditionalBonus = Type2AdditionalBonus(serviceCount + 1, serviceBonus.startTime, bonusAt(serviceBonus.startTime), baseBonusAt(serviceBonus.startTime), sumDays + serviceCount * (serviceBonus.startTime - epochDay).day)
    def removeService(serviceBonus: Type2Bonus): Type2AdditionalBonus = Type2AdditionalBonus(serviceCount - 1, serviceBonus.endTime, bonusAt(serviceBonus.endTime), baseBonusAt(serviceBonus.endTime) - Progression((serviceBonus.endTime - serviceBonus.startTime).day.let(it ⇒ it * it)), sumDays + serviceCount * (serviceBonus.endTime - epochDay).day - (serviceBonus.endTime - serviceBonus.startTime).day)
  }
}



Measured memory_bytes: 665864