Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
queries = list()
for ii in range(0,q):
  queries.append(input())
  
#print(queries)
# True -> straight, False -> back
order_flag = True

for query in queries:
  if query.startswith("1"):
    order_flag = not order_flag
  elif query.startswith("2"):
    if query[2] == "1":
      if order_flag:
        s = query[4] + s
      else:
        s = s + query[4]
    elif query[2] == "2":
      if order_flag:
        s = s + query[4]
      else:
        s = query[4] + s

if order_flag:
  print(s)
else:
  print(s[::-1])

Fixed submission:
from collections import deque

s = deque(list(input()))
#print(s)
q = int(input())
queries = list()
for ii in range(0,q):
  queries.append(input())
  
#print(queries)
# True -> straight, False -> back
order_flag = True

for query in queries:
  if query.startswith("1"):
    order_flag = not order_flag
  elif query.startswith("2"):
    if query[2] == "1":
      if order_flag:
        s.appendleft(query[4])
      else:
        s.append(query[4])
    elif query[2] == "2":
      if order_flag:
        s.append(query[4])
      else:
        s.appendleft(query[4])
        
if order_flag:
  print(''.join(list(s)))
else:
  s.reverse()
  print(''.join(list(s)))

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
queries = list()
for ii in range(0,q):
  queries.append(input())
  
#print(queries)

for query in queries:
  if query.startswith("1"):
    s = s[::-1]
  elif query.startswith("2"):
    if query[2] == "1":
      s = query[4] + s
    elif query[2] == "2":
      s = s + query[4]

print(s)

Fixed submission:
from collections import deque

s = deque(list(input()))
#print(s)
q = int(input())
queries = list()
for ii in range(0,q):
  queries.append(input())
  
#print(queries)
# True -> straight, False -> back
order_flag = True

for query in queries:
  if query.startswith("1"):
    order_flag = not order_flag
  elif query.startswith("2"):
    if query[2] == "1":
      if order_flag:
        s.appendleft(query[4])
      else:
        s.append(query[4])
    elif query[2] == "2":
      if order_flag:
        s.append(query[4])
      else:
        s.appendleft(query[4])
        
if order_flag:
  print(''.join(list(s)))
else:
  s.reverse()
  print(''.join(list(s)))

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
queries = list()
for ii in range(0,q):
  queries.append(input())
  
#print(queries)

for query in queries:
  if query.startswith("1"):
    s = s[::-1]
  elif query.startswith("2"):
    if query[2] == "1":
      s = query[4] + s
    elif query[2] == "2":
      s = s + query[4]

print(s)

Fixed submission:
from collections import deque

s = deque(list(input()))
#print(s)
q = int(input())
queries = list()
for ii in range(0,q):
  queries.append(input())
  
#print(queries)
# True -> straight, False -> back
order_flag = True

for query in queries:
  if query.startswith("1"):
    order_flag = not order_flag
  elif query.startswith("2"):
    if query[2] == "1":
      if order_flag:
        s.appendleft(query[4])
      else:
        s.append(query[4])
    elif query[2] == "2":
      if order_flag:
        s.append(query[4])
      else:
        s.appendleft(query[4])
        
if order_flag:
  print(''.join(list(s)))
else:
  s.reverse()
  print(''.join(list(s)))