S = eval(input())

Q = int(eval(input()))

bgn = ''

end = ''

is_inversion = False



for _ in range(Q):

    query = input().split()

    if query[0] == '1':

        if is_inversion:

            is_inversion = False

        else:

            is_inversion = True

    elif query[0] == '2':

        if query[1] == '1':

            if is_inversion:

                end += query[2]

            else:

                bgn += query[2]

        elif query[1] == '2':

            if is_inversion:

                bgn += query[2]

            else:

                end += query[2]

    





if is_inversion:

    ans = end[::-1] + S[::-1] + bgn

else:

    ans = bgn[::-1] + S + end



print(ans)
inversion = 1 #1 は反転していない、 -1 は反転している。

s = eval(input())

s1 = ""

s2 = ""

n_query = int(eval(input()))

for i in range(n_query):

    q = input().split()

    

    if q[0] == '1':

        inversion *= -1

    elif q[0] == '2':

        if inversion == 1:

            if q[1] == '1':

                s1 = s1 + q[2]

            elif q[1] == '2':

                s2 = s2 + q[2]

        elif inversion == -1:

            if q[1] == '1':

                s2 = s2 + q[2]

            elif q[1] == '2':

                s1 = s1 + q[2]



if inversion == 1:

    s = s1[::-1] + s + s2

elif inversion == -1:

    s = s2[::-1] + s[::-1] + s1



print(s)
S = eval(input())
Q = int(eval(input()))
bgn = ""
end = ""
is_inversion = False
for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        if is_inversion:
            is_inversion = False
        else:
            is_inversion = True
    elif query[0] == "2":
        if query[1] == "1":
            if is_inversion:
                end += query[2]
            else:
                bgn += query[2]
        elif query[1] == "2":
            if is_inversion:
                bgn += query[2]
            else:
                end += query[2]
if is_inversion:
    ans = end[::-1] + S[::-1] + bgn
else:
    ans = bgn[::-1] + S + end
print(ans)

inversion = 1  # 1 は反転していない、 -1 は反転している。
s = eval(input())
s1 = ""
s2 = ""
n_query = int(eval(input()))
for i in range(n_query):
    q = input().split()
    if q[0] == "1":
        inversion *= -1
    elif q[0] == "2":
        if inversion == 1:
            if q[1] == "1":
                s1 = s1 + q[2]
            elif q[1] == "2":
                s2 = s2 + q[2]
        elif inversion == -1:
            if q[1] == "1":
                s2 = s2 + q[2]
            elif q[1] == "2":
                s1 = s1 + q[2]
if inversion == 1:
    s = s1[::-1] + s + s2
elif inversion == -1:
    s = s2[::-1] + s[::-1] + s1
print(s)

-S = eval(input()) -Q = int(eval(input())) -bgn = "" -end = "" -is_inversion = False -for _ in range(Q): -    query = input().split() -    if query[0] == "1": -        if is_inversion: -            is_inversion = False -        else: -            is_inversion = True -    elif query[0] == "2": -        if query[1] == "1": -            if is_inversion: -                end += query[2] -            else: -                bgn += query[2] -        elif query[1] == "2": -            if is_inversion: -                bgn += query[2] -            else: -                end += query[2] -if is_inversion: -    ans = end[::-1] + S[::-1] + bgn -else: -    ans = bgn[::-1] + S + end -print(ans) +inversion = 1  # 1 は反転していない、 -1 は反転している。 +s = eval(input()) +s1 = "" +s2 = "" +n_query = int(eval(input())) +for i in range(n_query): +    q = input().split() +    if q[0] == "1": +        inversion *= -1 +    elif q[0] == "2": +        if inversion == 1: +            if q[1] == "1": +                s1 = s1 + q[2] +            elif q[1] == "2": +                s2 = s2 + q[2] +        elif inversion == -1: +            if q[1] == "1": +                s2 = s2 + q[2] +            elif q[1] == "2": +                s1 = s1 + q[2] +if inversion == 1: +    s = s1[::-1] + s + s2 +elif inversion == -1: +    s = s2[::-1] + s[::-1] + s1 +print(s)