Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
a = 0

for i in range(q):
    t = input().split()
    if t[0] == '2':
        if t[1] == '1' and a == 0 or t[1] == '2' and a == 1:
            s = ''.join([t[2], s])
        else:
            s = ''.join([s, t[2]])

    else:
        if a == 1:
            a = 0
        else:
            a = 1
        
if a == 1:
    print(s[::-1])
else:
    print(s)


Fixed submission:
s = input()
q = int(input())
Flag = False
right=''
left=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            right += c
        else:
            left += c

ans = left[::-1] + s + right
print(ans if not Flag else ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
a = 0

for i in range(q):
    t = input().split()
    if t[0] == '2':
        if t[1] == '1' and a == 0 or t[1] == '2' and a == 1:
            s = t[2] + s
        else:
            s += t[2]

    else:
        if a == 1:
            a = 0
        else:
            a = 1
        
if a == 1:
    print(s[::-1])
else:
    print(s)


Fixed submission:
s = input()
q = int(input())
Flag = False
right=''
left=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            right += c
        else:
            left += c

ans = left[::-1] + s + right
print(ans if not Flag else ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
a = 0

for i in range(q):
    t = input().split()
    if t[0] == '2':
        if t[1] == '1' and a == 0 or t[1] == '2' and a == 1:
            s = t[2] + s
        else:
            s += t[2]

    else:
        if a == 1:
            a = 0
        else:
            a = 1
        
if a == 1:
    print(s[::-1])
else:
    print(s)


Fixed submission:
s = input()
q = int(input())
Flag = False
right=''
left=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            right += c
        else:
            left += c

ans = left[::-1] + s + right
print(ans if not Flag else ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    t = input().split()
    if t[0] == '2':
        if t[1] == '1':
            s = t[2] + s
        else:
            s += t[2]
    else:
        s = s[::-1]

print(s)
 

Fixed submission:
s = input()
q = int(input())
Flag = False
right=''
left=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            right += c
        else:
            left += c

ans = left[::-1] + s + right
print(ans if not Flag else ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    t = input().split()
    if t[0] == '2':
        if t[1] == '1':
            s = t[2] + s
        else:
            s += t[2]
    else:
        s = s[::-1]

print(s)


Fixed submission:
s = input()
q = int(input())
Flag = False
right=''
left=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            right += c
        else:
            left += c

ans = left[::-1] + s + right
print(ans if not Flag else ans[::-1])