right = eval(input())

q = int(eval(input()))

left = ""

flag = 1

for i in range(q) :

    t = eval(input())

    if t == "1" :

        flag ^= 1

        continue

    t, f, c = t.split(" ")

    f = int(f)

    left += c*flag*(2-f)

    right += c*flag*(f-1)

    left += c*(1-flag)*(f-1)

    right += c*(1-flag)*(2-f)

if flag == 1 :

    print((left[::-1]+right))

else :

    print((right[::-1]+left))
right = eval(input())

flag = 1

left = ""

for i in range(int(eval(input()))):

    t = eval(input())

    if t == "1":

        flag ^= 1

        continue

    t, f, c = t.split(" ")

    if not ((f=="1")^flag):

        left += c

    else:

        right += c

ans = left[::-1] + right

if not flag:

    ans = ans[::-1]

print(ans)
right = eval(input())
q = int(eval(input()))
left = ""
flag = 1
for i in range(q):
    t = eval(input())
    if t == "1":
        flag ^= 1
        continue
    t, f, c = t.split(" ")
    f = int(f)
    left += c * flag * (2 - f)
    right += c * flag * (f - 1)
    left += c * (1 - flag) * (f - 1)
    right += c * (1 - flag) * (2 - f)
if flag == 1:
    print((left[::-1] + right))
else:
    print((right[::-1] + left))

right = eval(input())
flag = 1
left = ""
for i in range(int(eval(input()))):
    t = eval(input())
    if t == "1":
        flag ^= 1
        continue
    t, f, c = t.split(" ")
    if not ((f == "1") ^ flag):
        left += c
    else:
        right += c
ans = left[::-1] + right
if not flag:
    ans = ans[::-1]
print(ans)

-q = int(eval(input())) +flag = 1 -flag = 1 -for i in range(q): +for i in range(int(eval(input()))): -    f = int(f) -    left += c * flag * (2 - f) -    right += c * flag * (f - 1) -    left += c * (1 - flag) * (f - 1) -    right += c * (1 - flag) * (2 - f) -if flag == 1: -    print((left[::-1] + right)) -else: -    print((right[::-1] + left)) +    if not ((f == "1") ^ flag): +        left += c +    else: +        right += c +ans = left[::-1] + right +if not flag: +    ans = ans[::-1] +print(ans)