import sys

#input = sys.stdin.readline



S = str(eval(input()))

q = int(eval(input()))



p = ''

s = ''

cur = 0

for i in range(q):

    query = input().split()

    #print(query)

    if len(query) == 1:

        if cur == 0:

            cur = 1

        else:

            cur = 0

    else:

        t, f, c = query

        if f == '1':

            if cur == 0:

                p = c + p

            else:

                s = s + c

        else:

            if cur == 0:

                s  = s + c

            else:

                p = c + p

ans = p+S+s

if cur == 1:

    ans = ''.join(list(reversed(ans)))

print(ans)

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)))

import sys

# input = sys.stdin.readline
S = str(eval(input()))
q = int(eval(input()))
p = ""
s = ""
cur = 0
for i in range(q):
    query = input().split()
    # print(query)
    if len(query) == 1:
        if cur == 0:
            cur = 1
        else:
            cur = 0
    else:
        t, f, c = query
        if f == "1":
            if cur == 0:
                p = c + p
            else:
                s = s + c
        else:
            if cur == 0:
                s = s + c
            else:
                p = c + p
ans = p + S + s
if cur == 1:
    ans = "".join(list(reversed(ans)))
print(ans)

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)))

-import sys +s = list(str(eval(input()))) +q = int(eval(input())) +from collections import deque -# input = sys.stdin.readline -S = str(eval(input())) -q = int(eval(input())) -p = "" -s = "" -cur = 0 +s = deque(s) +cnt = 0 -    query = input().split() -    # print(query) +    query = list(map(str, input().split())) -        if cur == 0: -            cur = 1 -        else: -            cur = 0 +        cnt += 1 -            if cur == 0: -                p = c + p +            if cnt % 2 == 0: +                s.appendleft(c) -                s = s + c +                s.append(c) -            if cur == 0: -                s = s + c +            if cnt % 2 == 0: +                s.append(c) -                p = c + p -ans = p + S + s -if cur == 1: -    ans = "".join(list(reversed(ans))) -print(ans) +                s.appendleft(c) +s = list(s) +if cnt % 2 == 1: +    s.reverse() +print(("".join(s)))