/* Strategy
For example, "abcdefgh", h1 = 3, h2 = 2, h3 = 4.

initial "abcdefgh" = STR
h1 = 3  "defghabc" = STR.split(3, 8) + STR.split(0, 3)
h2 = 2  "fghabcde" = STR.split(5, 8) + STR.split(0, 5)
h3 = 4  "bcdefgha" = STR.split(1, 8) + STR.split(0, 1)
*/

//const config = { stdin: 'tmp', newline: '\r\n' }; // win
const config = { stdin: '/dev/stdin', newline: '\n' }; // linux

body = require('fs').readFileSync(config.stdin, 'ascii').split('\-')[0];
dataset = body.match(/[a-zA-Z]+[^a-zA-Z]+/g);
res = dataset.map(function (dataset) {
	var line, str, len, offset;
	line = dataset.trim().split(config.newline);
	str = line.shift();
	line.shift();
	len = str.length;
	offset = line.map(Number).reduce(add, 0) % len;
	return str.slice(offset, len) + str.slice(0, offset);
});

console.log(res.join('\n'));

function add(x, y) { return x + y; }