import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLine

object Main extends App {
  val lines = Iterator.continually(readLine()).takeWhile { _ != "-" }

  val datasets = {
    val buf = ListBuffer.empty[(String, Seq[Int])]

    while (lines.hasNext) {
      val line = lines.next()
      val m    = lines.next().toInt
      val xs   = Seq.fill(m)(lines.next().toInt)
      buf.append((line, xs))
    }

    buf.toList
  }

  val results = datasets.map {
    case (line, xs) =>
      xs.foldLeft(line) { (s, n) =>
        val (a, b) = s.splitAt(n)
        b + a
      }
  }

  results.foreach(println)
}

