# standard input

S = eval(input())

Q = int(eval(input()))

Query = []

num_reverse = 0



L = ''

R = ''



rev = False



for _ in range(Q):



    q = tuple(map(str, input().split()))



    if q[0] == '1':

        rev = (not rev)



    else:

        if (rev and q[1] == '1') or (not rev and q[1] == '2'):

            R = R + q[2]

        else:

            L = q[2] + L 



if rev:

    print(( R[::-1] + S[::-1] + L[::-1]))

else:

    print(( L + S + R ))

# standard input

S = eval(input())

Q = int(eval(input()))

Query = []

num_reverse = 0



L = []

R = []



rev = False



for _ in range(Q):



    q = tuple(map(str, input().split()))



    if q[0] == '1':

        rev = (not rev)



    else:

        if (rev and q[1] == '1') or (not rev and q[1] == '2'):

            R.append(q[2])

        else:

            L.append(q[2])



if rev:

    print((''.join(reversed(R)) + S[::-1] + ''.join(L)))

else:

    print((''.join(reversed(L)) + S + ''.join(R)))

# standard input
S = eval(input())
Q = int(eval(input()))
Query = []
num_reverse = 0
L = ""
R = ""
rev = False
for _ in range(Q):
    q = tuple(map(str, input().split()))
    if q[0] == "1":
        rev = not rev
    else:
        if (rev and q[1] == "1") or (not rev and q[1] == "2"):
            R = R + q[2]
        else:
            L = q[2] + L
if rev:
    print((R[::-1] + S[::-1] + L[::-1]))
else:
    print((L + S + R))

# standard input
S = eval(input())
Q = int(eval(input()))
Query = []
num_reverse = 0
L = []
R = []
rev = False
for _ in range(Q):
    q = tuple(map(str, input().split()))
    if q[0] == "1":
        rev = not rev
    else:
        if (rev and q[1] == "1") or (not rev and q[1] == "2"):
            R.append(q[2])
        else:
            L.append(q[2])
if rev:
    print(("".join(reversed(R)) + S[::-1] + "".join(L)))
else:
    print(("".join(reversed(L)) + S + "".join(R)))

-L = "" -R = "" +L = [] +R = [] -            R = R + q[2] +            R.append(q[2]) -            L = q[2] + L +            L.append(q[2]) -    print((R[::-1] + S[::-1] + L[::-1])) +    print(("".join(reversed(R)) + S[::-1] + "".join(L))) -    print((L + S + R)) +    print(("".join(reversed(L)) + S + "".join(R)))