#00016E

DynamicString

Maria's teacher gave her a difficult homework. Maria is to perform operations on a string and write the one she obtained after having performed all the operations. Maria did her homework, but she would like you to create a program that given a string and a list of operations performed on it, outputs the new string, so she could check if her result is correct.

Below is a description of the operations :
1 X S
Inserts the string S in reversed order in the actual string at position X. If X is greater than the actual string's length, inserts the string S in reversed order at the end of the actual string.
2 X
Deletes every Xth character in the actual string
3 C
Deletes every char C in the actual string
4 A B
Reverses the order of all characters from position A to position B in the actual
string ( 1 <= A <= B <= actual string's length )
5 X
Shifts the string X spaces to the right

1<=X<=32767 for all of the operations

InputThe first line of the input will contain a string S of Length<=150. However, the length of the string during the execution may vary up to 250. The following lines will contain one of the operations described above. Input is terminated with a line containing a zero number. The number of operations will not exceed 5000.


OutputOutput one line with the new string. If in any moment during the execution the string's length equaled 0, output -1.


Input
MAXIS
1 3 AGAT
2 2
3 G
4 2 3
3 T
1 1 AAA
5 2
2 3
0


Output
XSAA


Explanation :
MAXIS
MATAGAXIS
MTGXS
MTXS
MXTS
MXS
AAAMXS
XSAAAM
XSAA

Input
AABBCC
1 9 EEDD
3 A
3 B
3 C
4 1 4
3 D
3 E
2 2
1 1 CBA
2 3
0


Output
-1


Explanation :
AABBCC
AABBCCDDEE
BBCCDDEE
CCDDEE
DDEE
EEDD
EE


ABC
AB

After the 7th operation, the string's length equaled 0, so we output -1.

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.