from collections import deque

S = deque(list(input().strip()))

Q = int(eval(input()))

P = 0

for _ in range(Q):

    q = list(input().split())

    if q[0]=="1":

        P += 1

        P = P%2

    else:

        c = q[2]

        if q[1]=="1":

            if P==0:

                S.appendleft(c)

            else:

                S.append(c)

        else:

            if P==0:

                S.append(c)

            else:

                S.appendleft(c)

if P==1:

    S = list(S)

    S = S[::-1]

print(("".join(S)))
S = input().strip()

Q = int(eval(input()))

ind = 1

x = []

y = []

for i in range(Q):

    q = list(input().split())

    if len(q)==1:

        ind = ind*(-1)

    else:

        if q[1]=="1":

            if ind>0:

                x.append(q[2])

            else:

                y.append(q[2])

        else:

            if ind>0:

                y.append(q[2])

            else:

                x.append(q[2])

if ind>0:

    x = x[::-1]

    S = "".join(x)+S+"".join(y)

else:

    S = S[::-1]

    y = y[::-1]

    S = "".join(y)+S+"".join(x)

print(S)
from collections import deque

S = deque(list(input().strip()))
Q = int(eval(input()))
P = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        P += 1
        P = P % 2
    else:
        c = q[2]
        if q[1] == "1":
            if P == 0:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if P == 0:
                S.append(c)
            else:
                S.appendleft(c)
if P == 1:
    S = list(S)
    S = S[::-1]
print(("".join(S)))

S = input().strip()
Q = int(eval(input()))
ind = 1
x = []
y = []
for i in range(Q):
    q = list(input().split())
    if len(q) == 1:
        ind = ind * (-1)
    else:
        if q[1] == "1":
            if ind > 0:
                x.append(q[2])
            else:
                y.append(q[2])
        else:
            if ind > 0:
                y.append(q[2])
            else:
                x.append(q[2])
if ind > 0:
    x = x[::-1]
    S = "".join(x) + S + "".join(y)
else:
    S = S[::-1]
    y = y[::-1]
    S = "".join(y) + S + "".join(x)
print(S)

-from collections import deque - -S = deque(list(input().strip())) +S = input().strip() -P = 0 -for _ in range(Q): +ind = 1 +x = [] +y = [] +for i in range(Q): -    if q[0] == "1": -        P += 1 -        P = P % 2 +    if len(q) == 1: +        ind = ind * (-1) -        c = q[2] -            if P == 0: -                S.appendleft(c) +            if ind > 0: +                x.append(q[2]) -                S.append(c) +                y.append(q[2]) -            if P == 0: -                S.append(c) +            if ind > 0: +                y.append(q[2]) -                S.appendleft(c) -if P == 1: -    S = list(S) +                x.append(q[2]) +if ind > 0: +    x = x[::-1] +    S = "".join(x) + S + "".join(y) +else: -print(("".join(S))) +    y = y[::-1] +    S = "".join(y) + S + "".join(x) +print(S)