import sys

readline=sys.stdin.readline



S=readline().rstrip()

Q=int(readline())



cur=True

front=""

back=""

for i in range(Q):

  q=list(readline().rstrip().split())

  if q[0]=="1":

    cur^=True

  elif q[0]=="2":

    f,c=q[1],q[2]

    if f=="1":

      if cur:

        front+=c

      else:

        back+=c

    elif f=="2":

      if cur:

        back+=c

      else:

        front+=c

front=front[::-1]

ans=front+S+back

if not cur:

  ans=ans[::-1]

  

print(ans)

    

import sys

readline = sys.stdin.readline



S = readline().rstrip()



from collections import deque

S = deque(S)



Q = int(readline())

turn = False

for i in range(Q):

  query = readline().split()

  if query[0] == "1":

    turn ^= True

  elif query[0] == "2":

    if query[1] == "1":

      if turn:

        S.append(query[2])

      else:

        S.appendleft(query[2])

    elif query[1] == "2":

      if turn:

        S.appendleft(query[2])

      else:

        S.append(query[2])



S = "".join(S)

if turn:

  S = S[::-1]

  

print(S)
import sys

readline = sys.stdin.readline
S = readline().rstrip()
Q = int(readline())
cur = True
front = ""
back = ""
for i in range(Q):
    q = list(readline().rstrip().split())
    if q[0] == "1":
        cur ^= True
    elif q[0] == "2":
        f, c = q[1], q[2]
        if f == "1":
            if cur:
                front += c
            else:
                back += c
        elif f == "2":
            if cur:
                back += c
            else:
                front += c
front = front[::-1]
ans = front + S + back
if not cur:
    ans = ans[::-1]
print(ans)

import sys

readline = sys.stdin.readline
S = readline().rstrip()
from collections import deque

S = deque(S)
Q = int(readline())
turn = False
for i in range(Q):
    query = readline().split()
    if query[0] == "1":
        turn ^= True
    elif query[0] == "2":
        if query[1] == "1":
            if turn:
                S.append(query[2])
            else:
                S.appendleft(query[2])
        elif query[1] == "2":
            if turn:
                S.appendleft(query[2])
            else:
                S.append(query[2])
S = "".join(S)
if turn:
    S = S[::-1]
print(S)

+from collections import deque + +S = deque(S) -cur = True -front = "" -back = "" +turn = False -    q = list(readline().rstrip().split()) -    if q[0] == "1": -        cur ^= True -    elif q[0] == "2": -        f, c = q[1], q[2] -        if f == "1": -            if cur: -                front += c +    query = readline().split() +    if query[0] == "1": +        turn ^= True +    elif query[0] == "2": +        if query[1] == "1": +            if turn: +                S.append(query[2]) -                back += c -        elif f == "2": -            if cur: -                back += c +                S.appendleft(query[2]) +        elif query[1] == "2": +            if turn: +                S.appendleft(query[2]) -                front += c -front = front[::-1] -ans = front + S + back -if not cur: -    ans = ans[::-1] -print(ans) +                S.append(query[2]) +S = "".join(S) +if turn: +    S = S[::-1] +print(S)