import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;
import std.uni;
import std.range;
import std.algorithm;

void main()
{
    while (!stdin.eof)
    {
        auto a = readln.strip;
        if (a == "-")
            break;
        auto m = readln.strip.to!int;
        foreach (x; iota(m).map!(x => readln.strip.to!int))
        {
            a = a[x..$] ~ a[0..x];
        }
        writeln(a);
    }
}

