from collections import deque

S=deque(eval(input()))

q=int(eval(input()))

rev=False

for _ in range(q):

   inp=eval(input())

   if inp=="1":

      rev= not rev

   else:

      t,f,c=inp.split()

      if (rev and f=="1") or (not rev and f=="2"):

         S.append(c)

      else:

         S.appendleft(c)

if rev:

   S.reverse()

print(("".join(S)))
from collections import deque

que=deque(eval(input()))

q=int(eval(input()))

rev=False

for i in range(q):

    s=eval(input())

    if s=="1":

        rev= not rev

    else:

        t,f,c=s.split()

        if (f=='1' and rev==False) or (f=='2' and rev):

            que.appendleft(c)

        else:

            que.append(c)

A=que

if rev:

    A.reverse()

print(("".join(A)))
from collections import deque

S = deque(eval(input()))
q = int(eval(input()))
rev = False
for _ in range(q):
    inp = eval(input())
    if inp == "1":
        rev = not rev
    else:
        t, f, c = inp.split()
        if (rev and f == "1") or (not rev and f == "2"):
            S.append(c)
        else:
            S.appendleft(c)
if rev:
    S.reverse()
print(("".join(S)))

from collections import deque

que = deque(eval(input()))
q = int(eval(input()))
rev = False
for i in range(q):
    s = eval(input())
    if s == "1":
        rev = not rev
    else:
        t, f, c = s.split()
        if (f == "1" and rev == False) or (f == "2" and rev):
            que.appendleft(c)
        else:
            que.append(c)
A = que
if rev:
    A.reverse()
print(("".join(A)))

-S = deque(eval(input())) +que = deque(eval(input())) -for _ in range(q): -    inp = eval(input()) -    if inp == "1": +for i in range(q): +    s = eval(input()) +    if s == "1": -        t, f, c = inp.split() -        if (rev and f == "1") or (not rev and f == "2"): -            S.append(c) +        t, f, c = s.split() +        if (f == "1" and rev == False) or (f == "2" and rev): +            que.appendleft(c) -            S.appendleft(c) +            que.append(c) +A = que -    S.reverse() -print(("".join(S))) +    A.reverse() +print(("".join(A)))