from collections import deque



s=eval(input())

n=int(eval(input()))

q=deque()

q.append(s)

f=1

for i in range(n):

    t=list(input().split())

    if int(t[0])==1:

        f*=-1

    else:

        if f==1:

            if t[1]=='1' :

                q.appendleft(t[2])

            else:

                q.append(t[2])

        else:

            if t[1]=='2':

                q.appendleft(t[2])

            else:    

                q.append(t[2])

ans=''.join(q)

if f==-1:

    ans=ans[::-1]





print(ans)   
from collections import deque



s = eval(input())

Q = int(eval(input()))



l = deque()

l.append(s)



rev = True

for i in range(Q):

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

    if q[0] == "1":

        rev = not rev

    else:

        if rev:

            if q[1] == "1":

                l.appendleft(q[2])

            else:

                l.append(q[2])

        else:

            if q[1] == "1":

                l.append(q[2])

            else:

                l.appendleft(q[2])



ans = ""    

for i in l:

    ans += i



if not rev:

    print((ans[::-1]))

else:

    print(ans)
from collections import deque

s = eval(input())
n = int(eval(input()))
q = deque()
q.append(s)
f = 1
for i in range(n):
    t = list(input().split())
    if int(t[0]) == 1:
        f *= -1
    else:
        if f == 1:
            if t[1] == "1":
                q.appendleft(t[2])
            else:
                q.append(t[2])
        else:
            if t[1] == "2":
                q.appendleft(t[2])
            else:
                q.append(t[2])
ans = "".join(q)
if f == -1:
    ans = ans[::-1]
print(ans)

from collections import deque

s = eval(input())
Q = int(eval(input()))
l = deque()
l.append(s)
rev = True
for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        rev = not rev
    else:
        if rev:
            if q[1] == "1":
                l.appendleft(q[2])
            else:
                l.append(q[2])
        else:
            if q[1] == "1":
                l.append(q[2])
            else:
                l.appendleft(q[2])
ans = ""
for i in l:
    ans += i
if not rev:
    print((ans[::-1]))
else:
    print(ans)

-n = int(eval(input())) -q = deque() -q.append(s) -f = 1 -for i in range(n): -    t = list(input().split()) -    if int(t[0]) == 1: -        f *= -1 +Q = int(eval(input())) +l = deque() +l.append(s) +rev = True +for i in range(Q): +    q = list(input().split()) +    if q[0] == "1": +        rev = not rev -        if f == 1: -            if t[1] == "1": -                q.appendleft(t[2]) +        if rev: +            if q[1] == "1": +                l.appendleft(q[2]) -                q.append(t[2]) +                l.append(q[2]) -            if t[1] == "2": -                q.appendleft(t[2]) +            if q[1] == "1": +                l.append(q[2]) -                q.append(t[2]) -ans = "".join(q) -if f == -1: -    ans = ans[::-1] -print(ans) +                l.appendleft(q[2]) +ans = "" +for i in l: +    ans += i +if not rev: +    print((ans[::-1])) +else: +    print(ans)