# -*- coding: utf-8 -*-

S = str(eval(input()))

Q = int(eval(input()))



rev_flag = 1

head_str = ""

tail_str = ""

for _ in range(Q):

    query = list(map(str, input().split()))

    if query[0] == "1":

        rev_flag *= -1

    else:

        h_or_t_flag = 1 if query[1] == "1" else -1

        h_or_t_flag *= rev_flag

        

        if h_or_t_flag == 1:

            head_str = query[2] + head_str

        else:

            tail_str += query[2]



ans = head_str + S + tail_str

print((ans if rev_flag == 1 else ans[::-1]))
# -*- coding: utf-8 -*-

S = str(eval(input()))

Q = int(eval(input()))



rev_flag = 1

head_str = ""

tail_str = ""

for _ in range(Q):

    query = list(map(str, input().split()))

    if query[0] == "1":

        rev_flag *= -1

    else:

        h_or_t_flag = 1 if query[1] == "1" else -1

        h_or_t_flag *= rev_flag

        

        if h_or_t_flag == 1:

            head_str += query[2]

        else:

            tail_str += query[2]



ans = head_str[::-1] + S + tail_str

print((ans if rev_flag == 1 else ans[::-1]))
# -*- coding: utf-8 -*-
S = str(eval(input()))
Q = int(eval(input()))
rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        rev_flag *= -1
    else:
        h_or_t_flag = 1 if query[1] == "1" else -1
        h_or_t_flag *= rev_flag
        if h_or_t_flag == 1:
            head_str = query[2] + head_str
        else:
            tail_str += query[2]
ans = head_str + S + tail_str
print((ans if rev_flag == 1 else ans[::-1]))

# -*- coding: utf-8 -*-
S = str(eval(input()))
Q = int(eval(input()))
rev_flag = 1
head_str = ""
tail_str = ""
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        rev_flag *= -1
    else:
        h_or_t_flag = 1 if query[1] == "1" else -1
        h_or_t_flag *= rev_flag
        if h_or_t_flag == 1:
            head_str += query[2]
        else:
            tail_str += query[2]
ans = head_str[::-1] + S + tail_str
print((ans if rev_flag == 1 else ans[::-1]))

-            head_str = query[2] + head_str +            head_str += query[2] -ans = head_str + S + tail_str +ans = head_str[::-1] + S + tail_str