#include <stdio.h>
#include<string.h>

int main() {
    char str[40],r;
    int n,j;
    scanf("%s ",str);
    scanf("%d, %c",&n,r);
    int temp,len;
    len = strlen(str);
    for(int i=1;i<=n%len;i++){
        
        if(strcmp(r,'L') == 1){
            temp = str[0];
            for(j=0;j<len-1;j++){
                str[j] = str[j+1];
            }
            str[j] = temp;
        }
        else{
            temp = str[len-1];
            for(j=len-1;j>=1;j--){
                str[j] = str[j-1];
            }
            str[j] = temp;
            }
    }
    
    
    printf("%s",str);
    return 0;
}