var s:string;i,j,k,n:comp;begin repeat readln(k);read(s,n);for i:=1to abs(n)do for j:=1to k do write(s[j+(k-j*2+1)*ord(n<0)]);writeln until 0>0end.