/******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
String str = scan.nextLine();
int k=scan.nextInt();
String c=scan.next();
int rotate=k%str.length();
String str1="";
if(c.charAt(0)=='R'){
for(int i=(str.length()-rotate); i<str.length(); i++){
str1+=str.charAt(i);
}
str1=str1+str;
for(int i=0; i<str.length(); i++){
System.out.print(str1.charAt(i));
}
}
else if(c.charAt(0)=='L'){
for(int i=0; i<rotate; i++){
str1+=str.charAt(i);
}
str1=str+str1;
for(int i=rotate;i<str1.length();i++){
System.out.print(str1.charAt(i));
}
}
}
}