object Main {
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines
        for (cards <- in if cards != "-") {
            println(in.take(in.next.toInt).map(_.toInt).foldLeft(cards)((a, b) => a.drop(b) + a.take(b)))
        }
    }
}