from collections import deque

s = deque(input())

q = int(input())



t = 0

for _ in range(q):

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

  query[0] = int(query[0])

  if query[0] == 1: t = 1 - (t)

  else:

    if t == 0:

      if int(query[1]) == 1: s.appendleft(query[2])

      else: s.append(query[2])

    else:

      if int(query[1]) == 1: s.append(query[2])

      else: s.appendleft(query[2])

if t == 0: print(*s, sep = '')

else: print(*reversed(s), sep = '')

from collections import deque

s = eval(input())

q = int(eval(input()))



s = deque(s)

t = 0

for _ in range(q):

  query = list(map(str, input().split()))

  if query[0] == "1": t = 1 - t

  else:

    if t == 0:

      if query[1] == "1": s.appendleft(query[2])

      elif query[1] == "2": s.append(query[2])

    elif t == 1:

      if query[1] == "1": s.append(query[2])

      elif query[1] == "2": s.appendleft(query[2])

if t == 1:print(("".join(s)[::-1]))

else: print(("".join(s)))
from collections import deque

s = deque(input())
q = int(input())
t = 0
for _ in range(q):
    query = list(input().split())
    query[0] = int(query[0])
    if query[0] == 1:
        t = 1 - (t)
    else:
        if t == 0:
            if int(query[1]) == 1:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if int(query[1]) == 1:
                s.append(query[2])
            else:
                s.appendleft(query[2])
if t == 0:
    print(*s, sep="")
else:
    print(*reversed(s), sep="")

from collections import deque

s = eval(input())
q = int(eval(input()))
s = deque(s)
t = 0
for _ in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        t = 1 - t
    else:
        if t == 0:
            if query[1] == "1":
                s.appendleft(query[2])
            elif query[1] == "2":
                s.append(query[2])
        elif t == 1:
            if query[1] == "1":
                s.append(query[2])
            elif query[1] == "2":
                s.appendleft(query[2])
if t == 1:
    print(("".join(s)[::-1]))
else:
    print(("".join(s)))

-s = deque(input()) -q = int(input()) +s = eval(input()) +q = int(eval(input())) +s = deque(s) -    query = list(input().split()) -    query[0] = int(query[0]) -    if query[0] == 1: -        t = 1 - (t) +    query = list(map(str, input().split())) +    if query[0] == "1": +        t = 1 - t -            if int(query[1]) == 1: +            if query[1] == "1": -            else: +            elif query[1] == "2": -        else: -            if int(query[1]) == 1: +        elif t == 1: +            if query[1] == "1": -            else: +            elif query[1] == "2": -if t == 0: -    print(*s, sep="") +if t == 1: +    print(("".join(s)[::-1])) -    print(*reversed(s), sep="") +    print(("".join(s)))