object Main extends App {
  val scanner = new java.util.Scanner(System.in)
  
  val inputs = Iterator.continually {
    val cards = scanner.next()
    if(cards != "-") {
      val m = scanner.nextInt()
      val hs = (1 to m).map(_ => scanner.nextInt())

      (cards, m, hs)
    } else ("-", 0, Nil)   
  }.takeWhile(_._1 != "-")

  val outputs = inputs.map {
    case (cards, _, hs) =>
      hs.foldLeft(cards) { (acc, h) =>
        val (top, bot) = acc.splitAt(h)
        bot ++ top
      }
  }

  outputs.foreach(println)
}