S = eval(input())

Q = int(eval(input()))

Query = [eval(input()) for _ in range(Q)]

flag = True

s = "!"

for i in range(Q):

    if Query[i][0] == "1":

        if flag:

            flag = False

        else:

            flag = True

    else:

        if Query[i][2] == '1':

            if flag:

                s = Query[i][4] + s

            else:

                s = s + Query[i][4]

        else:

            if flag:

                s = s + Query[i][4]

            else:

                s = Query[i][4] + s

ans = s.replace("!", S)

if flag:

    print(ans)

else:

    print((ans[::-1]))
S = eval(input())

Q = int(eval(input()))

Query = [eval(input()) for _ in range(Q)]

flag = True

forward = ""

backward = ""

for i in range(Q):

    if Query[i][0] == "1":

        if flag:

            flag = False

        else:

            flag = True

    else:

        if Query[i][2] == '1':

            if flag:

                forward = Query[i][4] + forward

            else:

                backward = backward + Query[i][4]

        else:

            if flag:

                backward = backward + Query[i][4]

            else:

                forward = Query[i][4] + forward



if flag:

    ans = forward + S + backward

else:

    forward = forward[::-1]

    backward = backward[::-1]

    S = S[::-1]

    ans = backward + S + forward

print(ans)
S = eval(input())
Q = int(eval(input()))
Query = [eval(input()) for _ in range(Q)]
flag = True
s = "!"
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == "1":
            if flag:
                s = Query[i][4] + s
            else:
                s = s + Query[i][4]
        else:
            if flag:
                s = s + Query[i][4]
            else:
                s = Query[i][4] + s
ans = s.replace("!", S)
if flag:
    print(ans)
else:
    print((ans[::-1]))

S = eval(input())
Q = int(eval(input()))
Query = [eval(input()) for _ in range(Q)]
flag = True
forward = ""
backward = ""
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == "1":
            if flag:
                forward = Query[i][4] + forward
            else:
                backward = backward + Query[i][4]
        else:
            if flag:
                backward = backward + Query[i][4]
            else:
                forward = Query[i][4] + forward
if flag:
    ans = forward + S + backward
else:
    forward = forward[::-1]
    backward = backward[::-1]
    S = S[::-1]
    ans = backward + S + forward
print(ans)

-s = "!" +forward = "" +backward = "" -                s = Query[i][4] + s +                forward = Query[i][4] + forward -                s = s + Query[i][4] +                backward = backward + Query[i][4] -                s = s + Query[i][4] +                backward = backward + Query[i][4] -                s = Query[i][4] + s -ans = s.replace("!", S) +                forward = Query[i][4] + forward -    print(ans) +    ans = forward + S + backward -    print((ans[::-1])) +    forward = forward[::-1] +    backward = backward[::-1] +    S = S[::-1] +    ans = backward + S + forward +print(ans)