from collections import deque

S = deque(eval(input()))

Q = int(eval(input()))

query = [input().split() for _ in range(Q)]

reverse = False

for q in query:

    if q[0] == '1':

        reverse = not reverse

    else:

        if q[1] == '1':

            if not reverse:

                S.appendleft(q[2])

            else:

                S.append(q[2])

        else:

            if not reverse:

                S.append(q[2])

            else:

                S.appendleft(q[2])

if reverse:

    S.reverse()

print((''.join(S)))

from collections import deque

S = deque(eval(input()))

Q = int(eval(input()))

query = [input().split() for _ in range(Q)]

reverse = False

for q in query:

    if q[0] == '1':

        reverse = not reverse

    else:

        if q[1] == '1':

            S.append(q[2]) if reverse else S.appendleft(q[2])

        else:

            S.appendleft(q[2]) if reverse else S.append(q[2])

if reverse:

    S.reverse()

print((''.join(S)))
from collections import deque

S = deque(eval(input()))
Q = int(eval(input()))
query = [input().split() for _ in range(Q)]
reverse = False
for q in query:
    if q[0] == "1":
        reverse = not reverse
    else:
        if q[1] == "1":
            if not reverse:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if not reverse:
                S.append(q[2])
            else:
                S.appendleft(q[2])
if reverse:
    S.reverse()
print(("".join(S)))

from collections import deque

S = deque(eval(input()))
Q = int(eval(input()))
query = [input().split() for _ in range(Q)]
reverse = False
for q in query:
    if q[0] == "1":
        reverse = not reverse
    else:
        if q[1] == "1":
            S.append(q[2]) if reverse else S.appendleft(q[2])
        else:
            S.appendleft(q[2]) if reverse else S.append(q[2])
if reverse:
    S.reverse()
print(("".join(S)))

-            if not reverse: -                S.appendleft(q[2]) -            else: -                S.append(q[2]) +            S.append(q[2]) if reverse else S.appendleft(q[2]) -            if not reverse: -                S.append(q[2]) -            else: -                S.appendleft(q[2]) +            S.appendleft(q[2]) if reverse else S.append(q[2])