object Main extends App {
  val sc = new java.util.Scanner(System.in)
  execute(sc.next(), List.fill(sc.nextInt())(sc.nextInt()))

  def execute(cards: String, hList: List[Int]): Unit = {
    lazy val shuffle = makeShuffleFun(cards)
    cards match {
      case "-" => sc.close()
      case _ =>
        hList.foreach(shuffle(_))
        println(shuffle(0))
        execute(sc.next(), List.fill(sc.nextInt())(sc.nextInt()))
    }

    def makeShuffleFun(c: String): (Int) => String = {
      var cards = c
      (h: Int) => {
        if(h != 0) cards = cards.drop(h) ++ cards.take(h)
        cards
      }
    }
  }
}