function main(input){
    let lines = input.split("\n");
    let i = 0;
    let length = 0;
    let chars = "";
    while(lines[i]!=="-"){
        if(chars===""){
            chars=lines[i];
        }else if(length===0){
            length = lines[i];
        }else{
            for(let j=0;j<length;j++){
                let count = parseInt(lines[i+j]);
                let sliced = chars.slice(0,count);
                let rest = chars.slice(count);
                chars = rest+sliced;
            }
            i+=length-1;
            console.log(chars);
            chars="";
            length=0;
        }
        i++;
    }
    
}

main(require("fs").readFileSync("/dev/stdin","utf-8"));
