from collections import deque

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

q = int(eval(input()))



rev = 0

for i in range(q):

  tfc = list(input().split())

  if tfc[0] == "1":

    rev = abs(rev-1)

  else:

    t,f,c = tfc

    if rev:

      if f == "1":

        s.append(c)

      else:

        s.appendleft(c)

    else:

        if f == "1":

          s.appendleft(c)

        else:

          s.append(c)

if rev:

  t = []

  for i in range(len(s)):

    t.append(s.pop())

  print(("".join(t)))

else:

  print(("".join(s)))
s = eval(input())

q = int(eval(input()))



top = ""

isReverse = False

for i in range(q):

  qq = input().split()

  if qq[0] == "1":

    isReverse = not isReverse

  else:

    if qq[1] == "1":

      if isReverse: s+= qq[2]

      else: top += qq[2]

    else:

      if isReverse: top += qq[2]

      else: s+= qq[2]

        

if isReverse: s = s[::-1] + top

else: s = top[::-1] + s

print(s)
from collections import deque

s = deque(list(eval(input())))
q = int(eval(input()))
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0] == "1":
        rev = abs(rev - 1)
    else:
        t, f, c = tfc
        if rev:
            if f == "1":
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f == "1":
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(("".join(t)))
else:
    print(("".join(s)))

s = eval(input())
q = int(eval(input()))
top = ""
isReverse = False
for i in range(q):
    qq = input().split()
    if qq[0] == "1":
        isReverse = not isReverse
    else:
        if qq[1] == "1":
            if isReverse:
                s += qq[2]
            else:
                top += qq[2]
        else:
            if isReverse:
                top += qq[2]
            else:
                s += qq[2]
if isReverse:
    s = s[::-1] + top
else:
    s = top[::-1] + s
print(s)

-from collections import deque - -s = deque(list(eval(input()))) +s = eval(input()) -rev = 0 +top = "" +isReverse = False -    tfc = list(input().split()) -    if tfc[0] == "1": -        rev = abs(rev - 1) +    qq = input().split() +    if qq[0] == "1": +        isReverse = not isReverse -        t, f, c = tfc -        if rev: -            if f == "1": -                s.append(c) +        if qq[1] == "1": +            if isReverse: +                s += qq[2] -                s.appendleft(c) +                top += qq[2] -            if f == "1": -                s.appendleft(c) +            if isReverse: +                top += qq[2] -                s.append(c) -if rev: -    t = [] -    for i in range(len(s)): -        t.append(s.pop()) -    print(("".join(t))) +                s += qq[2] +if isReverse: +    s = s[::-1] + top -    print(("".join(s))) +    s = top[::-1] + s +print(s)