object Main extends App {
  val sc = new java.util.Scanner(System.in)

  while (sc.hasNext) {
    val cards = sc.next()
    if (cards == "-") sys.exit()
    val hList = List.fill(sc.nextInt())(sc.nextInt())
    execute(cards, hList)
  }

  def execute(cards: String, hList: List[Int]): Unit = {
    lazy val shuffle = makeShuffleFun(cards)
    hList.foreach(shuffle(_))
    println(shuffle(0))

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