s = eval(input())

d = True

f = '' # Front

b = '' # Back

q = int(eval(input()))

for _ in range(q):

    a = input().split()

    if a[0] == '1':

        d = not d

    else:

        if a[1] == '1':

            if d:

                f = ''.join([a[2], f])

            else:

                b = ''.join([b, a[2]])

        else:

            if d:

                b = ''.join([b, a[2]])

            else:

                f = ''.join([a[2], f])



if not d:

    print((''.join([b[::-1], s[::-1], f[::-1]])))

else:

    print((''.join([f, s, b])))

s = eval(input())

d = True

f = '' # Front

b = '' # Back

q = int(eval(input()))

for _ in range(q):

    a = input().split()

    if a[0] == '1':

        d = not d

    else:

        if a[1] == '1':

            if d:

                f = f + a[2]

            else:

                b = b + a[2]

        else:

            if d:

                b = b + a[2]

            else:

                f = f + a[2]



if not d:

    print((''.join([b[::-1], s[::-1], f])))

else:

    print((''.join([f[::-1], s, b])))

s = eval(input())
d = True
f = ""  # Front
b = ""  # Back
q = int(eval(input()))
for _ in range(q):
    a = input().split()
    if a[0] == "1":
        d = not d
    else:
        if a[1] == "1":
            if d:
                f = "".join([a[2], f])
            else:
                b = "".join([b, a[2]])
        else:
            if d:
                b = "".join([b, a[2]])
            else:
                f = "".join([a[2], f])
if not d:
    print(("".join([b[::-1], s[::-1], f[::-1]])))
else:
    print(("".join([f, s, b])))

s = eval(input())
d = True
f = ""  # Front
b = ""  # Back
q = int(eval(input()))
for _ in range(q):
    a = input().split()
    if a[0] == "1":
        d = not d
    else:
        if a[1] == "1":
            if d:
                f = f + a[2]
            else:
                b = b + a[2]
        else:
            if d:
                b = b + a[2]
            else:
                f = f + a[2]
if not d:
    print(("".join([b[::-1], s[::-1], f])))
else:
    print(("".join([f[::-1], s, b])))

-                f = "".join([a[2], f]) +                f = f + a[2] -                b = "".join([b, a[2]]) +                b = b + a[2] -                b = "".join([b, a[2]]) +                b = b + a[2] -                f = "".join([a[2], f]) +                f = f + a[2] -    print(("".join([b[::-1], s[::-1], f[::-1]]))) +    print(("".join([b[::-1], s[::-1], f]))) -    print(("".join([f, s, b]))) +    print(("".join([f[::-1], s, b])))