/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_9_B&lang=jp
  * String - Shuffle
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).takeWhile(_ != "-")
      .map {
        cards => {
          val n = io.StdIn.readInt()
          val shuffles = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).take(n).map(_.toInt)
          shuffles.foldLeft(cards) { (acc, x) =>
            val (lower, upper) = acc.splitAt(x)
            upper + lower
          }
        }
      }
      .foreach(println)
  }
}