S = eval(input())

Q = int(eval(input()))

f = True

l = []

r = []

for _ in range(Q):

    q = eval(input())

    if q == "1":

        f = not f

    else:

        _, F, C = q.split()

        if F == "1":

            t = l if f else r

            t.append(C)

        else:

            t = r if f else l

            t.append(C)

if f:

    l.reverse()

    ans = "".join(l) + S + "".join(r)

else:

    r.reverse()

    ans = "".join(r) + S[::-1] + "".join(l)

print(ans)
import sys

from collections import deque

S = deque(eval(input()))

Q = int(eval(input()))



reverse = False

for _ in range(Q):

    q = sys.stdin.readline()

    if q[0] == "1":

        reverse = not reverse

    else:

        _, f, c = q.split()

        if f == "1":

            if reverse:

                S.append(c)

            else:

                S.appendleft(c)

        else:

            if reverse:

                S.appendleft(c)

            else:

                S.append(c)

if reverse:

    S.reverse()

ans = "".join(S)

print(ans)
S = eval(input())
Q = int(eval(input()))
f = True
l = []
r = []
for _ in range(Q):
    q = eval(input())
    if q == "1":
        f = not f
    else:
        _, F, C = q.split()
        if F == "1":
            t = l if f else r
            t.append(C)
        else:
            t = r if f else l
            t.append(C)
if f:
    l.reverse()
    ans = "".join(l) + S + "".join(r)
else:
    r.reverse()
    ans = "".join(r) + S[::-1] + "".join(l)
print(ans)

import sys
from collections import deque

S = deque(eval(input()))
Q = int(eval(input()))
reverse = False
for _ in range(Q):
    q = sys.stdin.readline()
    if q[0] == "1":
        reverse = not reverse
    else:
        _, f, c = q.split()
        if f == "1":
            if reverse:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if reverse:
                S.appendleft(c)
            else:
                S.append(c)
if reverse:
    S.reverse()
ans = "".join(S)
print(ans)

-S = eval(input()) +import sys +from collections import deque + +S = deque(eval(input())) -f = True -l = [] -r = [] +reverse = False -    q = eval(input()) -    if q == "1": -        f = not f +    q = sys.stdin.readline() +    if q[0] == "1": +        reverse = not reverse -        _, F, C = q.split() -        if F == "1": -            t = l if f else r -            t.append(C) +        _, f, c = q.split() +        if f == "1": +            if reverse: +                S.append(c) +            else: +                S.appendleft(c) -            t = r if f else l -            t.append(C) -if f: -    l.reverse() -    ans = "".join(l) + S + "".join(r) -else: -    r.reverse() -    ans = "".join(r) + S[::-1] + "".join(l) +            if reverse: +                S.appendleft(c) +            else: +                S.append(c) +if reverse: +    S.reverse() +ans = "".join(S)