Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

S_list = list(S)

r = 1
a = []
b = []

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        r *= -1
        continue
    elif len(q) == 3:
        if q[1] == '1':
            if r == -1:
                b.append(q[2])
            else:
                a.insert(0, q[2])
        else:
            if r == -1:
                a.insert(0, q[2])
            else:
                b.append(q[2])
                
answer = a + S_list + b

if r == -1:
    answer = answer[::-1]
    
print(''.join(answer))

Fixed submission:
from collections import deque

S = input()
Q = int(input())

S_list = list(S)

r = 1
a = []
b = []
d = deque(a)

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        r *= -1
        continue
    elif len(q) == 3:
        if q[1] == '1':
            if r == -1:
                b.append(q[2])
            else:
                d.appendleft(q[2])
        else:
            if r == -1:
                d.appendleft(q[2])
            else:
                b.append(q[2])
                
answer = list(d) + S_list + b

if r == -1:
    answer = answer[::-1]
    
print(''.join(answer))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

S_list = list(S)

for i in range(Q):
    Query = input()
    #Query = Query.replace(' ', '')
    #Query = list(Query)
    T, F, C = 0, 0, ''
    if Query[0] == '2':
        T = int(Query[0])
        F = int(Query[2])
        C = Query[4]
    else:
        T = int(Query[0])
    
    if T == 1:
        S_list = S_list[::-1]
        
    if T == 2:
        if F == 1:
            S_list.insert(0, C)
        else:
            S_list.append(C)
            
print(''.join(S_list))

Fixed submission:
from collections import deque

S = input()
Q = int(input())

S_list = list(S)

r = 1
a = []
b = []
d = deque(a)

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        r *= -1
        continue
    elif len(q) == 3:
        if q[1] == '1':
            if r == -1:
                b.append(q[2])
            else:
                d.appendleft(q[2])
        else:
            if r == -1:
                d.appendleft(q[2])
            else:
                b.append(q[2])
                
answer = list(d) + S_list + b

if r == -1:
    answer = answer[::-1]
    
print(''.join(answer))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

S_list = list(S)

for i in range(Q):
    Query = input()
    #Query = Query.replace(' ', '')
    #Query = list(Query)
    T, F, C = 0, 0, ''
    if Query[0] == '2':
        T = int(Query[0])
        F = int(Query[2])
        C = Query[4]
    else:
        T = int(Query[0])
    
    if T == 1:
        S_list = S_list[::-1]
        
    if T == 2:
        if F == 1:
            S_list = S_list[::-1]
            S_list.append(C)
            S_list = S_list[::-1]
        else:
            S_list.append(C)
            
print(''.join(S_list))

Fixed submission:
from collections import deque

S = input()
Q = int(input())

S_list = list(S)

r = 1
a = []
b = []
d = deque(a)

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        r *= -1
        continue
    elif len(q) == 3:
        if q[1] == '1':
            if r == -1:
                b.append(q[2])
            else:
                d.appendleft(q[2])
        else:
            if r == -1:
                d.appendleft(q[2])
            else:
                b.append(q[2])
                
answer = list(d) + S_list + b

if r == -1:
    answer = answer[::-1]
    
print(''.join(answer))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

S_list = list(S)

for i in range(Q):
    Query = input()
    Query = Query.replace(' ', '')
    Query = list(Query)
    T, F, C = 0, 0, ''
    if len(Query) == 3:
        T = int(Query[0])
        F = int(Query[1])
        C = Query[2]
    else:
        T = int(Query[0])
    
    if T == 1:
        S_list = S_list[::-1]
        
    if T == 2:
        if F == 1:
            S_list = S_list[::-1]
            S_list.append(C)
            S_list = S_list[::-1]
        else:
            S_list.append(C)
            
print(''.join(S_list))

Fixed submission:
from collections import deque

S = input()
Q = int(input())

S_list = list(S)

r = 1
a = []
b = []
d = deque(a)

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        r *= -1
        continue
    elif len(q) == 3:
        if q[1] == '1':
            if r == -1:
                b.append(q[2])
            else:
                d.appendleft(q[2])
        else:
            if r == -1:
                d.appendleft(q[2])
            else:
                b.append(q[2])
                
answer = list(d) + S_list + b

if r == -1:
    answer = answer[::-1]
    
print(''.join(answer))