'use strict'

const main = arg => {
    var input = arg.trim().split("\n");
    const finalIndex = input.indexOf("-");
    input = input.slice(0, finalIndex);
    const mojiIndex = [];
    input.forEach((obj,i) => {
        if(obj.match(/[A-Za-z]/g)){
            mojiIndex.push(i);
        }
    });
    const loopNo = mojiIndex.length;
    const result = [];
    var firstIndex = 0;

    for(var i=0;i<loopNo;i++){
        var deck = input[firstIndex];
        const count = parseInt(input[firstIndex+1], 10);
        var shuffle = input.slice(firstIndex+2, firstIndex+2+count);
        firstIndex = firstIndex+2+count;

        shuffle.forEach(j => {
            const takeout = deck.slice(0, j);
            deck = deck.slice(j) + takeout;
        });
        result.push(deck);
    }

    console.log(result.join("\n"));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
