s=eval(input())

q=int(eval(input()))

l=""

r=""

flg=True



for i in range(q):

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

    if p[0]=="1":

        flg=not flg

    else:

        z,f,c=p

        if f=="1":

            if flg:

                l=c+l

            else:

                r=r+c

        else:

            if not flg:

                l=c+l

            else:

                r=r+c

s=l+s+r



if flg:

    ans=s

else:

    ans=s[::-1]

print(ans)
from collections import deque

s=deque(eval(input()))

q=int(eval(input()))

flg=True #正順

for i in range(q):

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

    if p[0]=="1":flg=not(flg)

    else:

        z,f,c=p

        if f=="1":

            if flg:s.appendleft(c)

            else:s.append(c)

        else:

            if not(flg):s.appendleft(c)

            else:s.append(c)



s=list(s)

if flg:

    ans=s

else:

    ans=s[::-1]

print(("".join(ans)))



s = eval(input())
q = int(eval(input()))
l = ""
r = ""
flg = True
for i in range(q):
    p = list(map(str, input().split()))
    if p[0] == "1":
        flg = not flg
    else:
        z, f, c = p
        if f == "1":
            if flg:
                l = c + l
            else:
                r = r + c
        else:
            if not flg:
                l = c + l
            else:
                r = r + c
s = l + s + r
if flg:
    ans = s
else:
    ans = s[::-1]
print(ans)

from collections import deque

s = deque(eval(input()))
q = int(eval(input()))
flg = True  # 正順
for i in range(q):
    p = list(map(str, input().split()))
    if p[0] == "1":
        flg = not (flg)
    else:
        z, f, c = p
        if f == "1":
            if flg:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if not (flg):
                s.appendleft(c)
            else:
                s.append(c)
s = list(s)
if flg:
    ans = s
else:
    ans = s[::-1]
print(("".join(ans)))

-s = eval(input()) +from collections import deque + +s = deque(eval(input())) -l = "" -r = "" -flg = True +flg = True  # 正順 -        flg = not flg +        flg = not (flg) -                l = c + l +                s.appendleft(c) -                r = r + c +                s.append(c) -            if not flg: -                l = c + l +            if not (flg): +                s.appendleft(c) -                r = r + c -s = l + s + r +                s.append(c) +s = list(s) -print(ans) +print(("".join(ans)))