process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  let i = 0;
  let s = lines[i++];
  while (i < lines.length && s !== "-") {
    i++;
    while (true) {
      let ss = lines[i++];
      const n = Number(ss);
      if (isNaN(n)) {
        console.log(s);
        s = ss;
        break;
      } else {
        s = s.slice(n) + s.slice(0, n);
      }
    }
  }
});

