#abc158d. [abc158_d]String Formation

[abc158_d]String Formation

Problem Statement

Takahashi has a string SS 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 QQ operations. In Operation ii (1leqileqQ)(1 \\leq i \\leq Q), an integer TiT_i is provided, which means the following:

  • If Ti=1T_i = 1: reverse the string SS.

  • If Ti=2T_i = 2: An integer FiF_i and a lowercase English letter CiC_i are additionally provided.

    • If Fi=1F_i = 1 : Add CiC_i to the beginning of the string SS.
    • If Fi=2F_i = 2 : Add CiC_i to the end of the string SS.

Help Takahashi by finding the final string that results from the procedure.

Constraints

  • 1leqSleq1051 \\leq |S| \\leq 10^5
  • SS consists of lowercase English letters.
  • 1leqQleq2times1051 \\leq Q \\leq 2 \\times 10^5
  • Ti=1T_i = 1 or 22.
  • Fi=1F_i = 1 or 22, if provided.
  • CiC_i is a lowercase English letter, if provided.

Input

Input is given from Standard Input in the following format:

SS QQ Query1Query_1 :: QueryQQuery_Q

In the 33-rd through the (Q+2)(Q+2)-th lines, QueryiQuery_i is one of the following:

11

which means Ti=1T_i = 1, and:

22 FiF_i CiC_i

which means Ti=2T_i = 2.

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 Q=4Q = 4 operations. Initially, SS is a.

  • Operation 11: Add p at the beginning of SS. SS becomes pa.

  • Operation 22: Reverse SS. SS becomes ap.

  • Operation 33: Add c at the end of SS. SS becomes apc.

  • Operation 44: Reverse SS. SS 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 Q=6Q = 6 operations. Initially, SS is a.

  • Operation 11: SS becomes aa.

  • Operation 22: SS becomes baa.

  • Operation 33: SS becomes aab.

  • Operation 44: SS becomes aabc.

  • Operation 55: SS becomes cbaa.

  • Operation 66: SS becomes aabc.

Thus, the resulting string is aabc.


Sample Input 3

y
1
2 1 x

Sample Output 3

xy