A notepad program currently has a string in it made up of lowercase letters in the english alphabet. The user performs actions. Each action, they can either copy a segment of the String into the clipboard or paste what's in the clipboard to the end of the string. After all actions, can you figure out what is?
The specifications for each instruction is given below:
Command Format | Description |
---|---|
C a b |
Copy the segment from to into the clipboard |
V |
Paste the string in the clipboard to the end of |
You can also assume that the segment to is in . The first action is guaranteed to be a copy action.
Constraints
Input Specification
The first line contains the string .
The second line contains the integer .
The next lines each describe an action.
Output Specification
One string, the final value of after all of the actions
Sample Input
abcdef
5
C 1 4
V
V
C 8 9
V
Sample Output
abcdefabcdabcdbc
Sample Explanation
We start with abcdef
. Copying , we have abcd
in the clipboard. Pasting twice, we get abcdefabcdabcd
. Copy , we have bc
in the clipboard. Pasting again gives abcdefabcdabcdbc
Comments