s = str(eval(input()))

q = int(eval(input()))



front_s = ''

back_s = ''

rev_flg = False



for i in range(q):

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

    if query[0] == '1':

        rev_flg = not rev_flg

    else:

        if not rev_flg:

            if query[1] == '1':

                front_s += query[2]

            else:

                back_s += query[2]

        else:

            if query[1] == '1':

                back_s += query[2]

            else:

                front_s += query[2]

    

res = front_s[::-1] + s + back_s

if rev_flg: res = res[::-1]

print(res) 
from collections import deque



s = list(eval(input()))

Q = int(eval(input()))

r = False



q = deque(s)

for _ in range(Q):

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

    if query[0] == '1':

        r = not r

    else:

        f,c = query[1],query[2]

        if f == '1':

            if not r:

                q.appendleft(c)

            else:

                q.append(c)

        else:

            if not r:

                q.append(c)

            else:

                q.appendleft(c)



ans = list(q)

if r: ans = ans[::-1]

print((''.join(ans)))

s = str(eval(input()))
q = int(eval(input()))
front_s = ""
back_s = ""
rev_flg = False
for i in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        rev_flg = not rev_flg
    else:
        if not rev_flg:
            if query[1] == "1":
                front_s += query[2]
            else:
                back_s += query[2]
        else:
            if query[1] == "1":
                back_s += query[2]
            else:
                front_s += query[2]
res = front_s[::-1] + s + back_s
if rev_flg:
    res = res[::-1]
print(res)

from collections import deque

s = list(eval(input()))
Q = int(eval(input()))
r = False
q = deque(s)
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        r = not r
    else:
        f, c = query[1], query[2]
        if f == "1":
            if not r:
                q.appendleft(c)
            else:
                q.append(c)
        else:
            if not r:
                q.append(c)
            else:
                q.appendleft(c)
ans = list(q)
if r:
    ans = ans[::-1]
print(("".join(ans)))

-s = str(eval(input())) -q = int(eval(input())) -front_s = "" -back_s = "" -rev_flg = False -for i in range(q): +from collections import deque + +s = list(eval(input())) +Q = int(eval(input())) +r = False +q = deque(s) +for _ in range(Q): -        rev_flg = not rev_flg +        r = not r -        if not rev_flg: -            if query[1] == "1": -                front_s += query[2] +        f, c = query[1], query[2] +        if f == "1": +            if not r: +                q.appendleft(c) -                back_s += query[2] +                q.append(c) -            if query[1] == "1": -                back_s += query[2] +            if not r: +                q.append(c) -                front_s += query[2] -res = front_s[::-1] + s + back_s -if rev_flg: -    res = res[::-1] -print(res) +                q.appendleft(c) +ans = list(q) +if r: +    ans = ans[::-1] +print(("".join(ans)))