from collections import deque

s=deque(list(eval(input())))

q=int(eval(input()))

direction=0 #0:順 1:逆



for i in range(q):

    query=list(input().split())

    i=int(query[0])

    if i==1:

        direction=direction^1

    elif i==2:

        f,c=int(query[1]),query[2]

        if f==1 and direction==0:

            s.appendleft(c)

        elif f==1 and direction==1:

            s.append(c)

        elif f==2 and direction==0:

            s.append(c)

        elif f==2 and direction==1:

            s.appendleft(c)



if direction==0:

    print((''.join(s)))

else:

    s=''.join(s)

    s=s[::-1]

    print(s)

from collections import deque

s=deque(list(eval(input())))

q=int(eval(input()))

direction=0 #0:順 1:逆



for i in range(q):

    query=eval(input())

    if query[0]=='1':

        direction=direction^1

    elif query[0]=='2':

        i,f,c=query.split()

        if f=='1' and direction==0:

            s.appendleft(c)

        elif f=='1' and direction==1:

            s.append(c)

        elif f=='2' and direction==0:

            s.append(c)

        elif f=='2' and direction==1:

            s.appendleft(c)





if direction==0:

    print((''.join(s)))

else:

    s=''.join(s)

    s=s[::-1]

    print(s)

from collections import deque

s = deque(list(eval(input())))
q = int(eval(input()))
direction = 0  # 0:順 1:逆
for i in range(q):
    query = list(input().split())
    i = int(query[0])
    if i == 1:
        direction = direction ^ 1
    elif i == 2:
        f, c = int(query[1]), query[2]
        if f == 1 and direction == 0:
            s.appendleft(c)
        elif f == 1 and direction == 1:
            s.append(c)
        elif f == 2 and direction == 0:
            s.append(c)
        elif f == 2 and direction == 1:
            s.appendleft(c)
if direction == 0:
    print(("".join(s)))
else:
    s = "".join(s)
    s = s[::-1]
    print(s)

from collections import deque

s = deque(list(eval(input())))
q = int(eval(input()))
direction = 0  # 0:順 1:逆
for i in range(q):
    query = eval(input())
    if query[0] == "1":
        direction = direction ^ 1
    elif query[0] == "2":
        i, f, c = query.split()
        if f == "1" and direction == 0:
            s.appendleft(c)
        elif f == "1" and direction == 1:
            s.append(c)
        elif f == "2" and direction == 0:
            s.append(c)
        elif f == "2" and direction == 1:
            s.appendleft(c)
if direction == 0:
    print(("".join(s)))
else:
    s = "".join(s)
    s = s[::-1]
    print(s)

-    query = list(input().split()) -    i = int(query[0]) -    if i == 1: +    query = eval(input()) +    if query[0] == "1": -    elif i == 2: -        f, c = int(query[1]), query[2] -        if f == 1 and direction == 0: +    elif query[0] == "2": +        i, f, c = query.split() +        if f == "1" and direction == 0: -        elif f == 1 and direction == 1: +        elif f == "1" and direction == 1: -        elif f == 2 and direction == 0: +        elif f == "2" and direction == 0: -        elif f == 2 and direction == 1: +        elif f == "2" and direction == 1: