S=eval(input())

Q=int(eval(input()))



X=[]

Y=[]

f=1

for _ in range(Q):

    A=list(input().split())

    if A[0]=="1":

        f*=-1

    if A[0]=="2":

        if A[1]=="1":

            if f==1:

                X.append(A[2])

            if f==-1:

                Y.append(A[2])

        if A[1]=="2":

            if f==-1:

                X.append(A[2])

            if f==1:

                Y.append(A[2])



x="".join(X)

x="".join(list(reversed(x)))

y="".join(Y)



a=[x,S,y]

b="".join(a)



if f==-1:

    b="".join(list(reversed(b)))



print(b)

from collections import deque

S=eval(input())

Q=int(eval(input()))



X=deque(S)

f=1

for _ in range(Q):

    A=list(input().split())

    if A[0]=="1":

        f*=-1

    if A[0]=="2":

        if A[1]=="1":

            if f==1:

                X.appendleft(A[2])

            if f==-1:

                X.append(A[2])

        if A[1]=="2":

            if f==-1:

                X.appendleft(A[2])

            if f==1:

                X.append(A[2])



if f==-1:

    print(("".join(list(reversed(X)))))

else:

    print(("".join(list(X))))
S = eval(input())
Q = int(eval(input()))
X = []
Y = []
f = 1
for _ in range(Q):
    A = list(input().split())
    if A[0] == "1":
        f *= -1
    if A[0] == "2":
        if A[1] == "1":
            if f == 1:
                X.append(A[2])
            if f == -1:
                Y.append(A[2])
        if A[1] == "2":
            if f == -1:
                X.append(A[2])
            if f == 1:
                Y.append(A[2])
x = "".join(X)
x = "".join(list(reversed(x)))
y = "".join(Y)
a = [x, S, y]
b = "".join(a)
if f == -1:
    b = "".join(list(reversed(b)))
print(b)

from collections import deque

S = eval(input())
Q = int(eval(input()))
X = deque(S)
f = 1
for _ in range(Q):
    A = list(input().split())
    if A[0] == "1":
        f *= -1
    if A[0] == "2":
        if A[1] == "1":
            if f == 1:
                X.appendleft(A[2])
            if f == -1:
                X.append(A[2])
        if A[1] == "2":
            if f == -1:
                X.appendleft(A[2])
            if f == 1:
                X.append(A[2])
if f == -1:
    print(("".join(list(reversed(X)))))
else:
    print(("".join(list(X))))

+from collections import deque + -X = [] -Y = [] +X = deque(S) +                X.appendleft(A[2]) +            if f == -1: -            if f == -1: -                Y.append(A[2]) +                X.appendleft(A[2]) +            if f == 1: -            if f == 1: -                Y.append(A[2]) -x = "".join(X) -x = "".join(list(reversed(x))) -y = "".join(Y) -a = [x, S, y] -b = "".join(a) -    b = "".join(list(reversed(b))) -print(b) +    print(("".join(list(reversed(X))))) +else: +    print(("".join(list(X))))