S = eval(input())

Q = int(eval(input()))

QUERY = []

for i in range(Q):

    # q = list(map(int, input().split()))

    q = input().split()

    if q[0] == '1':

        QUERY.append([int(q[0])])

    else:

        QUERY.append([int(q[0]), int(q[1]), q[2]])



st = []

en = []

rev = False

rev_c = 0

for q in QUERY:

    if q[0] == 1:

        if rev:

            rev = False

        else:

            rev = True

        rev_c += 1

    else:

        if q[1] == 1:

            if not rev:

                st.append(q[2])

            else:

                en.append(q[2])

        else:

            if not rev:

                en.append(q[2])

            else:

                st.append(q[2])



# print(st)

# print(en)



st_s = "".join(st)

st_s = st_s[::-1]

en_s = "".join(en)



ans = st_s + S + en_s

if rev_c % 2 == 0:

    pass

else:

    ans = ans[::-1]



print(ans)
S = eval(input())

Q = int(eval(input()))

QUERY = []

for i in range(Q):

    q = input().split()

    QUERY.append(q)



from collections import deque



l = deque(list(S))

# print(l)



rev = 0

for qi in QUERY:

    if qi[0] == '1':

        rev += 1

    else:

        if rev % 2 == 0:

            if qi[1] == '1':

                l.appendleft(qi[2])

            else:

                l.append(qi[2])

        else:

            if qi[1] == '1':

                l.append(qi[2])

            else:

                l.appendleft(qi[2])



# print(l)

ans = "".join(l)

# print(ans)

if rev % 2 != 0:

    ans = ans[::-1]



print(ans)
S = eval(input())
Q = int(eval(input()))
QUERY = []
for i in range(Q):
    # q = list(map(int, input().split()))
    q = input().split()
    if q[0] == "1":
        QUERY.append([int(q[0])])
    else:
        QUERY.append([int(q[0]), int(q[1]), q[2]])
st = []
en = []
rev = False
rev_c = 0
for q in QUERY:
    if q[0] == 1:
        if rev:
            rev = False
        else:
            rev = True
        rev_c += 1
    else:
        if q[1] == 1:
            if not rev:
                st.append(q[2])
            else:
                en.append(q[2])
        else:
            if not rev:
                en.append(q[2])
            else:
                st.append(q[2])
# print(st)
# print(en)
st_s = "".join(st)
st_s = st_s[::-1]
en_s = "".join(en)
ans = st_s + S + en_s
if rev_c % 2 == 0:
    pass
else:
    ans = ans[::-1]
print(ans)

S = eval(input())
Q = int(eval(input()))
QUERY = []
for i in range(Q):
    q = input().split()
    QUERY.append(q)
from collections import deque

l = deque(list(S))
# print(l)
rev = 0
for qi in QUERY:
    if qi[0] == "1":
        rev += 1
    else:
        if rev % 2 == 0:
            if qi[1] == "1":
                l.appendleft(qi[2])
            else:
                l.append(qi[2])
        else:
            if qi[1] == "1":
                l.append(qi[2])
            else:
                l.appendleft(qi[2])
# print(l)
ans = "".join(l)
# print(ans)
if rev % 2 != 0:
    ans = ans[::-1]
print(ans)

-    # q = list(map(int, input().split())) -    if q[0] == "1": -        QUERY.append([int(q[0])]) +    QUERY.append(q) +from collections import deque + +l = deque(list(S)) +# print(l) +rev = 0 +for qi in QUERY: +    if qi[0] == "1": +        rev += 1 -        QUERY.append([int(q[0]), int(q[1]), q[2]]) -st = [] -en = [] -rev = False -rev_c = 0 -for q in QUERY: -    if q[0] == 1: -        if rev: -            rev = False +        if rev % 2 == 0: +            if qi[1] == "1": +                l.appendleft(qi[2]) +            else: +                l.append(qi[2]) -            rev = True -        rev_c += 1 -    else: -        if q[1] == 1: -            if not rev: -                st.append(q[2]) +            if qi[1] == "1": +                l.append(qi[2]) -                en.append(q[2]) -        else: -            if not rev: -                en.append(q[2]) -            else: -                st.append(q[2]) -# print(st) -# print(en) -st_s = "".join(st) -st_s = st_s[::-1] -en_s = "".join(en) -ans = st_s + S + en_s -if rev_c % 2 == 0: -    pass -else: +                l.appendleft(qi[2]) +# print(l) +ans = "".join(l) +# print(ans) +if rev % 2 != 0: