s = list(str(eval(input())))

q = int(eval(input()))



from collections import deque

s = deque(s)



cnt = 0



for i in range(q):

    query = list(map(str, input().split()))

    if len(query) == 1:

        cnt += 1

    else:

        t, f, c = query

        if f == '1':

            if cnt%2 == 0:

                s.appendleft(c)

            else:

                s.append(c)

        else:

            if cnt%2 == 0:

                s.append(c)

            else:

                s.appendleft(c)

s = list(s)

if cnt%2 == 1:

    s.reverse()

print((''.join(s)))

s = list(str(eval(input())))

q = int(eval(input()))

flag = 1

from collections import deque

s = deque(s)

for i in range(q):

    query = list(map(str, input().split()))

    if len(query) == 1:

        flag = 1-flag

    else:

        t, f, c = query

        if f == '1':

            if flag:

                s.appendleft(c)

            else:

                s.append(c)

        else:

            if flag:

                s.append(c)

            else:

                s.appendleft(c)



s = list(s)

if not flag:

    s.reverse()

print((''.join(s)))

s = list(str(eval(input())))
q = int(eval(input()))
from collections import deque

s = deque(s)
cnt = 0
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        cnt += 1
    else:
        t, f, c = query
        if f == "1":
            if cnt % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if cnt % 2 == 0:
                s.append(c)
            else:
                s.appendleft(c)
s = list(s)
if cnt % 2 == 1:
    s.reverse()
print(("".join(s)))

s = list(str(eval(input())))
q = int(eval(input()))
flag = 1
from collections import deque

s = deque(s)
for i in range(q):
    query = list(map(str, input().split()))
    if len(query) == 1:
        flag = 1 - flag
    else:
        t, f, c = query
        if f == "1":
            if flag:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if flag:
                s.append(c)
            else:
                s.appendleft(c)
s = list(s)
if not flag:
    s.reverse()
print(("".join(s)))

+flag = 1 -cnt = 0 -        cnt += 1 +        flag = 1 - flag -            if cnt % 2 == 0: +            if flag: -            if cnt % 2 == 0: +            if flag: -if cnt % 2 == 1: +if not flag: