import scala.util.control.Breaks
object Main extends App {
  val b = new Breaks
  b.breakable {
    while(true) {
      var deck = readLine

      if (deck == "-") b.break

      val m = readLine.toInt

      for (k <- 0 until m) {
        val h = readLine.toInt
        val (head, tail) = deck.splitAt(h)
        deck = tail + head
      }
      println(deck)
    }
  }
}
