S=eval(input())

q=int(eval(input()))

RV=0

A="A"

for i in range(q):

    IN=eval(input())

    if IN=="1":

        RV+=1

    else:

        t,f,c=IN.split()

        if RV%2==0:

            if f=="1":

                A=c+A               

            else:

                A=A+c

        else:

            if f=="1":

                A=A+c

            else:

                A=c+A

if RV%2==0:

    for i in range(len(A)):

        if A[i]=="A":

            print((A[:i]+S+A[i+1:]))

else:

    A=A[::-1]

    for i in range(len(A)):

        if A[i]=="A":

            print((A[:i]+S[::-1]+A[i+1:]))
S=eval(input())

q=int(eval(input()))

rev=False

pre=''

for i in range(q):

    inp=eval(input())

    if inp[0]=="1":

        rev=not rev

    else:

        t,f,c=inp.split()

        if (f=='1' and rev) or (f=='2' and not rev):

            S+=c

        else:

            pre+=c

if not rev:

    print((pre[::-1]+S))

else:

    print((S[::-1]+pre))
S = eval(input())
q = int(eval(input()))
RV = 0
A = "A"
for i in range(q):
    IN = eval(input())
    if IN == "1":
        RV += 1
    else:
        t, f, c = IN.split()
        if RV % 2 == 0:
            if f == "1":
                A = c + A
            else:
                A = A + c
        else:
            if f == "1":
                A = A + c
            else:
                A = c + A
if RV % 2 == 0:
    for i in range(len(A)):
        if A[i] == "A":
            print((A[:i] + S + A[i + 1 :]))
else:
    A = A[::-1]
    for i in range(len(A)):
        if A[i] == "A":
            print((A[:i] + S[::-1] + A[i + 1 :]))

S = eval(input())
q = int(eval(input()))
rev = False
pre = ""
for i in range(q):
    inp = eval(input())
    if inp[0] == "1":
        rev = not rev
    else:
        t, f, c = inp.split()
        if (f == "1" and rev) or (f == "2" and not rev):
            S += c
        else:
            pre += c
if not rev:
    print((pre[::-1] + S))
else:
    print((S[::-1] + pre))

-RV = 0 -A = "A" +rev = False +pre = "" -    IN = eval(input()) -    if IN == "1": -        RV += 1 +    inp = eval(input()) +    if inp[0] == "1": +        rev = not rev -        t, f, c = IN.split() -        if RV % 2 == 0: -            if f == "1": -                A = c + A -            else: -                A = A + c +        t, f, c = inp.split() +        if (f == "1" and rev) or (f == "2" and not rev): +            S += c -            if f == "1": -                A = A + c -            else: -                A = c + A -if RV % 2 == 0: -    for i in range(len(A)): -        if A[i] == "A": -            print((A[:i] + S + A[i + 1 :])) +            pre += c +if not rev: +    print((pre[::-1] + S)) -    A = A[::-1] -    for i in range(len(A)): -        if A[i] == "A": -            print((A[:i] + S[::-1] + A[i + 1 :])) +    print((S[::-1] + pre))