S=eval(input())

Q=int(eval(input()))

Rev=True

front=''

back=''

for i in range(Q):

    a=eval(input())

    if a=='1':

        Rev=not(Rev)

    else:

        b,c,x=a.split()

        if c == '1':

            if Rev:

                front += x

            else:

                back += x

        else:

            if Rev:

                back += x

            else:

                front += x

if Rev:

    print((front[::-1] + S + back))

else:

    print((back[::-1]+S[::-1]+front))

S=list(eval(input()))

Q=int(eval(input()))

Rev=True

front=[]

back=[]

for i in range(Q):

    a=eval(input())

    if a=='1':

        Rev=not(Rev)

    else:

        b,c,x=a.split()

        if c == '1':

            if Rev:

                front.append(x)

            else:

                back.append(x)

        else:

            if Rev:

                back.append(x)

            else:

                front.append(x)

if Rev:

    front.reverse()

    front.extend(S)

    front.extend(back)

    print(("".join(front)))

else:

    back.reverse()

    S.reverse()

    back.extend(S)

    back.extend(front)

    print(("".join(back)))

S = eval(input())
Q = int(eval(input()))
Rev = True
front = ""
back = ""
for i in range(Q):
    a = eval(input())
    if a == "1":
        Rev = not (Rev)
    else:
        b, c, x = a.split()
        if c == "1":
            if Rev:
                front += x
            else:
                back += x
        else:
            if Rev:
                back += x
            else:
                front += x
if Rev:
    print((front[::-1] + S + back))
else:
    print((back[::-1] + S[::-1] + front))

S = list(eval(input()))
Q = int(eval(input()))
Rev = True
front = []
back = []
for i in range(Q):
    a = eval(input())
    if a == "1":
        Rev = not (Rev)
    else:
        b, c, x = a.split()
        if c == "1":
            if Rev:
                front.append(x)
            else:
                back.append(x)
        else:
            if Rev:
                back.append(x)
            else:
                front.append(x)
if Rev:
    front.reverse()
    front.extend(S)
    front.extend(back)
    print(("".join(front)))
else:
    back.reverse()
    S.reverse()
    back.extend(S)
    back.extend(front)
    print(("".join(back)))

-S = eval(input()) +S = list(eval(input())) -front = "" -back = "" +front = [] +back = [] -                front += x +                front.append(x) -                back += x +                back.append(x) -                back += x +                back.append(x) -                front += x +                front.append(x) -    print((front[::-1] + S + back)) +    front.reverse() +    front.extend(S) +    front.extend(back) +    print(("".join(front))) -    print((back[::-1] + S[::-1] + front)) +    back.reverse() +    S.reverse() +    back.extend(S) +    back.extend(front) +    print(("".join(back)))