#abc158d. [abc158_d]String Formation
[abc158_d]String Formation
Problem Statement
Takahashi has a string consisting of lowercase English letters.
Starting with this string, he will produce a new one in the procedure given as follows.
The procedure consists of operations. In Operation , an integer is provided, which means the following:
-
If : reverse the string .
-
If : An integer and a lowercase English letter are additionally provided.
- If : Add to the beginning of the string .
- If : Add to the end of the string .
Help Takahashi by finding the final string that results from the procedure.
Constraints
- consists of lowercase English letters.
- or .
- or , if provided.
- is a lowercase English letter, if provided.
Input
Input is given from Standard Input in the following format:
In the -rd through the -th lines, is one of the following:
which means , and:
which means .
Output
Print the resulting string.
Sample Input 1
a
4
2 1 p
1
2 2 c
1
Sample Output 1
cpa
There will be operations. Initially, is a
.
-
Operation : Add
p
at the beginning of . becomespa
. -
Operation : Reverse . becomes
ap
. -
Operation : Add
c
at the end of . becomesapc
. -
Operation : Reverse . becomes
cpa
.
Thus, the resulting string is cpa
.
Sample Input 2
a
6
2 2 a
2 1 b
1
2 2 c
1
1
Sample Output 2
aabc
There will be operations. Initially, is a
.
-
Operation : becomes
aa
. -
Operation : becomes
baa
. -
Operation : becomes
aab
. -
Operation : becomes
aabc
. -
Operation : becomes
cbaa
. -
Operation : becomes
aabc
.
Thus, the resulting string is aabc
.
Sample Input 3
y
1
2 1 x
Sample Output 3
xy