s = eval(input())

s = list(s)

 

q=int(eval(input()))

front=[]

back=[]

hantei = True

for _ in range(q):

    t = input().split()

    if t[0] == '1':

        hantei = not hantei

    else:

        if hantei:

            if t[1] == '1':

                front.append(t[2])

            else:

                back.append(t[2])

        else:

            if t[1] == '2':

                front.append(t[2])

            else:

                back.append(t[2])



if hantei:

    front.reverse()

    ans = front + s + back 

else:

    back.reverse()

    s.reverse()

    ans = back + s + front

print((''.join(map(str,ans))))
S = list(eval(input()))

N = int(eval(input()))

normalFlag = True

front = []

back = []

for _ in range(N):

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

    if q[0] == '1':

        normalFlag = not normalFlag

    else:

        if q[1] == '1':

            if normalFlag:

                front.append(q[2])

            else:

                back.append(q[2])

        else:

            if normalFlag:

                back.append(q[2])

            else:

                front.append(q[2])



if normalFlag:

    front.reverse()

    ans = front+S+back

else:

    back.reverse()

    S.reverse()

    ans = back+S+front

print((''.join(map(str,ans))))
s = eval(input())
s = list(s)
q = int(eval(input()))
front = []
back = []
hantei = True
for _ in range(q):
    t = input().split()
    if t[0] == "1":
        hantei = not hantei
    else:
        if hantei:
            if t[1] == "1":
                front.append(t[2])
            else:
                back.append(t[2])
        else:
            if t[1] == "2":
                front.append(t[2])
            else:
                back.append(t[2])
if hantei:
    front.reverse()
    ans = front + s + back
else:
    back.reverse()
    s.reverse()
    ans = back + s + front
print(("".join(map(str, ans))))

S = list(eval(input()))
N = int(eval(input()))
normalFlag = True
front = []
back = []
for _ in range(N):
    q = list(map(str, input().split()))
    if q[0] == "1":
        normalFlag = not normalFlag
    else:
        if q[1] == "1":
            if normalFlag:
                front.append(q[2])
            else:
                back.append(q[2])
        else:
            if normalFlag:
                back.append(q[2])
            else:
                front.append(q[2])
if normalFlag:
    front.reverse()
    ans = front + S + back
else:
    back.reverse()
    S.reverse()
    ans = back + S + front
print(("".join(map(str, ans))))

-s = eval(input()) -s = list(s) -q = int(eval(input())) +S = list(eval(input())) +N = int(eval(input())) +normalFlag = True -hantei = True -for _ in range(q): -    t = input().split() -    if t[0] == "1": -        hantei = not hantei +for _ in range(N): +    q = list(map(str, input().split())) +    if q[0] == "1": +        normalFlag = not normalFlag -        if hantei: -            if t[1] == "1": -                front.append(t[2]) +        if q[1] == "1": +            if normalFlag: +                front.append(q[2]) -                back.append(t[2]) +                back.append(q[2]) -            if t[1] == "2": -                front.append(t[2]) +            if normalFlag: +                back.append(q[2]) -                back.append(t[2]) -if hantei: +                front.append(q[2]) +if normalFlag: -    ans = front + s + back +    ans = front + S + back -    s.reverse() -    ans = back + s + front +    S.reverse() +    ans = back + S + front