s = eval(input())

q = int(eval(input()))



f1 = 1

f2 = 2



st = ""

se = ""



for _ in range(q):

    q = input().split()

    if int(q[0]) == 1:

        f1,f2 = f2,f1

    elif int(q[0]) == 2:

            if int(q[1]) == f1:

                st = q[2] + st

            elif int(q[1]) == f2:

                se += q[2]



ans = st + s + se

if f1 == 1:

    print(ans)

else:

    ans = list(ans)

    ans.reverse()

    ans = "".join(ans)

    print(ans)
from collections import deque



s = eval(input())

q = int(eval(input()))



dt = deque()

de = deque()



f1 = 1

f2 = 2



for _ in range(q):

    q = input().split()

    if int(q[0]) == 1:

        f1,f2 = f2,f1

    elif int(q[0]) == 2:

            if int(q[1]) == f1:

                dt.appendleft(q[2])

            elif int(q[1]) == f2:

                de.append(q[2])

                

st = "".join(dt)

se = "".join(de)

ans = st + s + se



if f1 == 1:

    print(ans)

else:

    ans = list(ans)

    ans.reverse()

    ans = "".join(ans)

    print(ans)
s = eval(input())
q = int(eval(input()))
f1 = 1
f2 = 2
st = ""
se = ""
for _ in range(q):
    q = input().split()
    if int(q[0]) == 1:
        f1, f2 = f2, f1
    elif int(q[0]) == 2:
        if int(q[1]) == f1:
            st = q[2] + st
        elif int(q[1]) == f2:
            se += q[2]
ans = st + s + se
if f1 == 1:
    print(ans)
else:
    ans = list(ans)
    ans.reverse()
    ans = "".join(ans)
    print(ans)

from collections import deque

s = eval(input())
q = int(eval(input()))
dt = deque()
de = deque()
f1 = 1
f2 = 2
for _ in range(q):
    q = input().split()
    if int(q[0]) == 1:
        f1, f2 = f2, f1
    elif int(q[0]) == 2:
        if int(q[1]) == f1:
            dt.appendleft(q[2])
        elif int(q[1]) == f2:
            de.append(q[2])
st = "".join(dt)
se = "".join(de)
ans = st + s + se
if f1 == 1:
    print(ans)
else:
    ans = list(ans)
    ans.reverse()
    ans = "".join(ans)
    print(ans)

+from collections import deque + +dt = deque() +de = deque() -st = "" -se = "" -            st = q[2] + st +            dt.appendleft(q[2]) -            se += q[2] +            de.append(q[2]) +st = "".join(dt) +se = "".join(de)