Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
query = [input().split() for i in range(Q)]
for i in query:
    # if i[0] == '1':
    if len(i) == 1:
        S.reverse()
    elif i[1]=='1':
        S.appendleft(i[2])
    # elif i[0]=='2' and i[1]=='2':
    else:
        S.append(i[2])
print(''.join(list(S)))



Fixed submission:
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
reverse = 1
query = [input().split() for i in range(Q)]
for i in query:
    if len(i) == 1:
        reverse *= -1
    elif (i[1]=='1' and reverse == 1) or (i[1]=='2' and reverse==-1):
        S.appendleft(i[2])
    else:
        S.append(i[2])
if reverse == -1:
   S.reverse() 
print(''.join(list(S)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
query = [input().split() for i in range(Q)]
for i in query:
    if i[0] == '1':
        S.reverse()
    elif i[0]=='2' and i[1]=='1':
        S.appendleft(i[2])
    # elif i[0]=='2' and i[1]=='2':
    else:
        S.append(i[2])
print(''.join(list(S)))

Fixed submission:
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
reverse = 1
query = [input().split() for i in range(Q)]
for i in query:
    if len(i) == 1:
        reverse *= -1
    elif (i[1]=='1' and reverse == 1) or (i[1]=='2' and reverse==-1):
        S.appendleft(i[2])
    else:
        S.append(i[2])
if reverse == -1:
   S.reverse() 
print(''.join(list(S)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
query = [input().split() for i in range(Q)]
for i in query:
    if i[0] == '1':
        S.reverse()
    elif i[0]=='2' and i[1]=='1':
        # S.insert(0, i[2])
        S.appendleft(i[2])
    elif i[0]=='2' and i[1]=='2':
        S.append(i[2])
print(''.join(list(S)))


Fixed submission:
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
reverse = 1
query = [input().split() for i in range(Q)]
for i in query:
    if len(i) == 1:
        reverse *= -1
    elif (i[1]=='1' and reverse == 1) or (i[1]=='2' and reverse==-1):
        S.appendleft(i[2])
    else:
        S.append(i[2])
if reverse == -1:
   S.reverse() 
print(''.join(list(S)))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
query = [input().split() for i in range(Q)]
for i in query:
    if i[0] == '1':
        S = list(reversed(S))
    elif i[0]=='2' and i[1]=='1':
        S.insert(0, i[2])
    elif i[0]=='2' and i[1]=='2':
        S.append(i[2])
print(''.join(S))

Fixed submission:
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
reverse = 1
query = [input().split() for i in range(Q)]
for i in query:
    if len(i) == 1:
        reverse *= -1
    elif (i[1]=='1' and reverse == 1) or (i[1]=='2' and reverse==-1):
        S.appendleft(i[2])
    else:
        S.append(i[2])
if reverse == -1:
   S.reverse() 
print(''.join(list(S)))

Buggy python submission (verdict: Runtime Error):
S = list(input())
Q = int(input())
query = [input().split() for i in range(Q)]
print(query)
for i in query:
    # print(i)
    if i[0] == '1':
        
        S = list(reversed(S))
        print(S)
    elif i[0]=='2' and i[1]=='1':
        S.insert(0, i[2])
        print(S)
    elif i[0]=='2' and i[1]=='2':
        S.append(i[2])
        print(S)
print(''.join(S))


Fixed submission:
from collections import deque

S = list(input())
S = deque(S)
Q = int(input())
reverse = 1
query = [input().split() for i in range(Q)]
for i in query:
    if len(i) == 1:
        reverse *= -1
    elif (i[1]=='1' and reverse == 1) or (i[1]=='2' and reverse==-1):
        S.appendleft(i[2])
    else:
        S.append(i[2])
if reverse == -1:
   S.reverse() 
print(''.join(list(S)))