const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const arr = input.split('\n');
let cards = [];
let str = '';
for(let i=0; i<arr.length; i++){
  if(arr[i] === '-') break;
  if(/\d+/.test(arr[i])) continue;
  if(/[a-z]/.test(arr[i])) {
    cards = arr[i].split('');
    rep = Number(arr[i+1]);
    for(let j=i+2; j<i+2+rep; j++){
      const num = Number(arr[j]);
      const move = cards.splice(num);
      cards = move.concat(cards);
    }
    str += cards.join('') + '\n';
  }
}
console.log(str.trim());
