const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
for (let i=0; i<input.length; i++) {
    if (input[i] === '-') {break;}
    let time = Number(input[i+1]);
    let shaffle = [];
    let word = input[i].split('')
    for (let j=0; j<time; j++) {
    let num = Number(input[i+2+j]);
    let array = word.splice(num);
    word = array.concat(word);
     }
     i = i + time +1;
     console.log(word.join(''));
}
