from collections import deque

s = eval(input())

q = int(eval(input()))

queue = deque([s])



tmp = 1

for i in range(q):

    x = eval(input())

    if x[0]==str(1):

        tmp*=-1

    else:

        t,f,c = x.split()

        t,f = int(t),int(f)

        if tmp==-1:

            if f==1:

                queue.append(c)

            if f==2:

                queue.appendleft(c)

        if tmp==1:

            if f==1:

                queue.appendleft(c)

            if f==2:

                queue.append(c)



print((''.join(queue)[::tmp]))
from collections import deque



s = eval(input())

q = int(eval(input()))



deq = deque([s])

flag = 1

for i in range(q):

    query = input().split()

    if query[0]==str(1):

        flag*=-1 

    if query[0]==str(2):

        x = 1 if query[1]==str(1) else -1

        if flag*x==1:

            deq.appendleft(query[2])

        else:

            deq.append(query[2])



if flag==-1:

    print((''.join(deq)[::-1]))

else:

    print((''.join(deq)))
from collections import deque

s = eval(input())
q = int(eval(input()))
queue = deque([s])
tmp = 1
for i in range(q):
    x = eval(input())
    if x[0] == str(1):
        tmp *= -1
    else:
        t, f, c = x.split()
        t, f = int(t), int(f)
        if tmp == -1:
            if f == 1:
                queue.append(c)
            if f == 2:
                queue.appendleft(c)
        if tmp == 1:
            if f == 1:
                queue.appendleft(c)
            if f == 2:
                queue.append(c)
print(("".join(queue)[::tmp]))

from collections import deque

s = eval(input())
q = int(eval(input()))
deq = deque([s])
flag = 1
for i in range(q):
    query = input().split()
    if query[0] == str(1):
        flag *= -1
    if query[0] == str(2):
        x = 1 if query[1] == str(1) else -1
        if flag * x == 1:
            deq.appendleft(query[2])
        else:
            deq.append(query[2])
if flag == -1:
    print(("".join(deq)[::-1]))
else:
    print(("".join(deq)))

-queue = deque([s]) -tmp = 1 +deq = deque([s]) +flag = 1 -    x = eval(input()) -    if x[0] == str(1): -        tmp *= -1 -    else: -        t, f, c = x.split() -        t, f = int(t), int(f) -        if tmp == -1: -            if f == 1: -                queue.append(c) -            if f == 2: -                queue.appendleft(c) -        if tmp == 1: -            if f == 1: -                queue.appendleft(c) -            if f == 2: -                queue.append(c) -print(("".join(queue)[::tmp])) +    query = input().split() +    if query[0] == str(1): +        flag *= -1 +    if query[0] == str(2): +        x = 1 if query[1] == str(1) else -1 +        if flag * x == 1: +            deq.appendleft(query[2]) +        else: +            deq.append(query[2]) +if flag == -1: +    print(("".join(deq)[::-1])) +else: +    print(("".join(deq)))