var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");

  var i = 0;
  while (true) {
    if (input[i] == "-") {
      break;
    }
    
    var text = input[i++];
    var m = parseInt(input[i++], 10);
    
    for (j = 0; j < m; j++) {
      var h = parseInt(input[i + j]);
      text = text.slice(h) + text.slice(0, h);
    }
    console.log(text);
    i += m;
  }
});