/**

 * Paul Shen

 * Holmdel High School

 * Senior 3 Division

 * ACSL Contest #3 2005-2006

 */

 

import java.io.*;

import java.util.*;

 

 

public class ACSLStrings {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

 

        for(int i = 0; i < 5; i++)

        {

            System.out.print((i + 1) + ": ");

            String input = br.readLine();

            StringTokenizer st = new StringTokenizer(input, "/");

            String[] tokens = new String[st.countTokens()];

            for(int t = 0; st.hasMoreTokens(); t++)

            {

                tokens[t] = st.nextToken();

            }

            String word = tokens[tokens.length - 1];

            for(int c = 0; c < tokens.length - 1; c++)

            {

                word = process(word, tokens[c]);

            }

            System.out.println(word);

        }

    }

 

    private static String process(String word, String command)

    {

        StringTokenizer st = new StringTokenizer(command, "-");

        String cfunct = st.nextToken();

        String parameter = st.nextToken();

        if(cfunct.equals("LS"))

        {

            return shift(word, Integer.parseInt(parameter), 'L');

        }

        if(cfunct.equals("RS"))

        {

            return shift(word, Integer.parseInt(parameter), 'R');

        }

        if(cfunct.equals("LC"))

        {

            return cycle(word, Integer.parseInt(parameter), 'L');

        }

        if(cfunct.equals("RC"))

        {

            return cycle(word, Integer.parseInt(parameter), 'R');

        }

        if(cfunct.equals("MC"))

        {

            return mcycle(word, Integer.parseInt(parameter.substring(0, 1)), Integer.parseInt(parameter.substring(1, 2)), Integer.parseInt(parameter.substring(2, 3)), parameter.charAt(3));

        }

        if(cfunct.equals("REV"))

        {

            return reverse(word, Integer.parseInt(parameter.substring(0, 1)), Integer.parseInt(parameter.substring(1, 2)));

        }

        if(cfunct.equals("SWAP"))

        {

            return swap(word, Integer.parseInt(parameter.substring(0, 1)), Integer.parseInt(parameter.substring(1, 2)), Integer.parseInt(parameter.substring(2, 3)));

        }

        if(cfunct.equals("SORT"))

        {

            return ssort(word, Integer.parseInt(parameter.substring(0, 1)), Integer.parseInt(parameter.substring(1, 2)), parameter.charAt(2));

        }

        return "Unrecognized command";

    }

 

    private static String shift(String word, int x, char direction) {

        if(x > word.length())

        {

            String newWord = "";

            for(int i = 0; i < word.length(); i++)

            {

                newWord += "#";

            }

            return newWord;

        }

        String newWord = "";

        if (direction == 'L') {

            newWord = word.substring(x);

            for (int i = 0; i < x; i++) {

                newWord = newWord + "#";

            }

        } else {

            newWord = word.substring(0, word.length() - x);

            for (int i = 0; i < x; i++) {

                newWord = "#" + newWord;

            }

        }

        return newWord;

    }

 

    private static String cycle(String word, int x, char direction) {

        String newWord = "";

        x %= word.length();

        if (direction == 'L') {

            newWord = word.substring(x) + word.substring(0, x);

        } else {

            newWord = word.substring(word.length() - x) + word.substring(0, word.length() - x);

        }

        return newWord;

    }

 

    private static String mcycle(String word, int s, int l, int x, char direction) {

        s--;

        String newWord = word.substring(0, s) + cycle(word.substring(s, s + l), x, direction) + word.substring(s + l);

        return newWord;

    }

 

    private static String reverse(String word, int s, int l)

    {

        s--;

        String midReversed = new StringBuffer(word.substring(s, s + l)).reverse().toString();

        String newWord = word.substring(0, s) + midReversed + word.substring(s + l);

        return newWord;

    }

 

    private static String swap(String word, int s, int l, int p)

    {

        s--;

        p--;

        String sPart = word.substring(s, s + l);

        String pPart = word.substring(p, p + l);

        String newWord = "";

        if(s < p)

        {

            newWord = word.substring(0, s) + pPart + word.substring(s + l, p) + sPart + word.substring(p + l);

        } else {

            newWord = word.substring(0, p) + sPart + word.substring(p + l, s) + pPart + word.substring(s + l);

        }

        return newWord;

    }

 

    private static String ssort(String word, int s, int l, char m)

    {

        s--;

        char[] letters = new char[l];

        word.getChars(s, s + l, letters, 0);

        Arrays.sort(letters);

        String sortedPart = new String(letters);

        if(m == 'D')

        {

            sortedPart = reverse(sortedPart, 1, sortedPart.length());

        }

        String newWord = word.substring(0, s) + sortedPart + word.substring(s + l);

        return newWord;

    }

}