Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
d = deque(s)
for i in range(q):
    if array[i][0] == "1":
        d.reverse()
    elif array[i][1] == "1":
        d.appendleft(array[i][2])
    elif array[i][1] == "2":
        d.append(array[i][2])
d_str = "".join(list(d))
print(d_str)

Fixed submission:
from collections import deque
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
#print(array)
d = deque(s)
reverse = 1
for i in range(q):
    if array[i][0] == "1":
        reverse *= -1
    elif (array[i][1] == "1") and (reverse == 1):
        d.appendleft(array[i][2])
    elif (array[i][1] == "1") and (reverse == -1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == 1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == -1):
        d.appendleft(array[i][2])

if reverse == -1:
    d.reverse()

d_str = "".join(list(d))
print(d_str)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
d = deque(s)
for i in range(q):
    if array[i][0] == "1":
        d.reverse()
    elif array[i][1] == "1":
        d.appendleft(array[i][2])
    elif array[i][1] == "2":
        d.append(array[i][2])
d_str = "".join(list(d))
print(d_str)

Fixed submission:
from collections import deque
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
#print(array)
d = deque(s)
reverse = 1
for i in range(q):
    if array[i][0] == "1":
        reverse *= -1
    elif (array[i][1] == "1") and (reverse == 1):
        d.appendleft(array[i][2])
    elif (array[i][1] == "1") and (reverse == -1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == 1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == -1):
        d.appendleft(array[i][2])

if reverse == -1:
    d.reverse()

d_str = "".join(list(d))
print(d_str)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
#print(array)
for i in range(q):
    if array[i][0] == "1":
        s = s[::-1]
    elif array[i][1] == "1":
        s = array[i][2] + s
    elif array[i][1] == "2":
        s = s + array[i][2]
print(s)

Fixed submission:
from collections import deque
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
#print(array)
d = deque(s)
reverse = 1
for i in range(q):
    if array[i][0] == "1":
        reverse *= -1
    elif (array[i][1] == "1") and (reverse == 1):
        d.appendleft(array[i][2])
    elif (array[i][1] == "1") and (reverse == -1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == 1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == -1):
        d.appendleft(array[i][2])

if reverse == -1:
    d.reverse()

d_str = "".join(list(d))
print(d_str)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
#print(array)
for i in range(q):
    if array[i][0] == "1":
        s = s[::-1]
    elif array[i][1] == "1":
        s = array[i][2] + s
    elif array[i][1] == "2":
        s = s + array[i][2]
print(s)

Fixed submission:
from collections import deque
s = input()
q = int(input())
array = [list(map(str, input().split())) for i in range(q)]
#print(array)
d = deque(s)
reverse = 1
for i in range(q):
    if array[i][0] == "1":
        reverse *= -1
    elif (array[i][1] == "1") and (reverse == 1):
        d.appendleft(array[i][2])
    elif (array[i][1] == "1") and (reverse == -1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == 1):
        d.append(array[i][2])
    elif (array[i][1] == "2") and (reverse == -1):
        d.appendleft(array[i][2])

if reverse == -1:
    d.reverse()

d_str = "".join(list(d))
print(d_str)