Buggy python submission (verdict: Runtime Error):
from collections import deque

string = input()
s = deque(string)
iteration = int(input())
reverse = 1

for c in range(0,iteration):
    sousa = input().split()
    #操作１のとき
    if sousa[0] == "1":
        reverse = reverse*(-1)
    #操作２を行うとき
    elif sousa[1] == "1":
        if reverse == 1:
            s.appendleft(sousa[2])
        else:
            s.append(sousa[2])
    else:
        if reverse == 1:
            s.append(sousa[2])
        else:
            s.appendleft(sousa[2])

if reverse == -1:
    s = s[::-1]

result = "".join(s)
print(result)


Fixed submission:
from collections import deque
string = input()
s = deque(string)
iteration = int(input())
reverse = 1

for c in range(0,iteration):
    sousa = input().split()
    #操作１のとき
    if sousa[0] == "1":
        reverse = reverse*(-1)
    #操作２を行うとき
    elif sousa[1] == "1":
        if reverse == 1:
            s.appendleft(sousa[2])
        else:
            s.append(sousa[2])
    else:
        if reverse == 1:
            s.append(sousa[2])
        else:
            s.appendleft(sousa[2])

result = "".join(s)
if reverse == -1:
    result = result[::-1]


print(result)

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

for c in range(0,iteration):
    sousa = input().split()
    if sousa[0] == "1":
        s = s[:: -1]
    elif sousa[1] == "1":
        s = sousa[2] + s
    else:
        s = s + sousa[2]
print(s)


Fixed submission:
from collections import deque
string = input()
s = deque(string)
iteration = int(input())
reverse = 1

for c in range(0,iteration):
    sousa = input().split()
    #操作１のとき
    if sousa[0] == "1":
        reverse = reverse*(-1)
    #操作２を行うとき
    elif sousa[1] == "1":
        if reverse == 1:
            s.appendleft(sousa[2])
        else:
            s.append(sousa[2])
    else:
        if reverse == 1:
            s.append(sousa[2])
        else:
            s.appendleft(sousa[2])

result = "".join(s)
if reverse == -1:
    result = result[::-1]


print(result)

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

for c in range(0,iteration):
    sousa = input().split()
    if sousa[0] == "1":
        s = s[:: -1]
    elif sousa[1] == "1":
        s = sousa[2] + s
    else:
        s = s + sousa[2]
print(s)

Fixed submission:
from collections import deque
string = input()
s = deque(string)
iteration = int(input())
reverse = 1

for c in range(0,iteration):
    sousa = input().split()
    #操作１のとき
    if sousa[0] == "1":
        reverse = reverse*(-1)
    #操作２を行うとき
    elif sousa[1] == "1":
        if reverse == 1:
            s.appendleft(sousa[2])
        else:
            s.append(sousa[2])
    else:
        if reverse == 1:
            s.append(sousa[2])
        else:
            s.appendleft(sousa[2])

result = "".join(s)
if reverse == -1:
    result = result[::-1]


print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
iteration = int(input())
sousa_list = []
for i in range(0,iteration):
    sousa = input().split()
    sousa_list.append(sousa)

for c in range(0,iteration):
    if sousa_list[c][0] == "1":
        s = s[:: -1]
    else:
        if sousa_list[c][1] == "1":
            s = sousa_list[c][2] + s
        else:
            s = s + sousa_list[c][2]
print(s)

Fixed submission:
from collections import deque
string = input()
s = deque(string)
iteration = int(input())
reverse = 1

for c in range(0,iteration):
    sousa = input().split()
    #操作１のとき
    if sousa[0] == "1":
        reverse = reverse*(-1)
    #操作２を行うとき
    elif sousa[1] == "1":
        if reverse == 1:
            s.appendleft(sousa[2])
        else:
            s.append(sousa[2])
    else:
        if reverse == 1:
            s.append(sousa[2])
        else:
            s.appendleft(sousa[2])

result = "".join(s)
if reverse == -1:
    result = result[::-1]


print(result)