Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
a = list(input())
Q = int(input())
A = []
d = deque(a)
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    d.reverse()
  elif b[1] == "1":
    d.appendleft(b[2])
  elif b[1] == "2":
    d.append(b[2])
print("".join(d))

Fixed submission:
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
a = list(input())
Q = int(input())
B = []
C = []
A = [list(input().split()) for _ in range(Q)]
d = deque(a)
for i in range(len(A)):
  if len(A[i]) == 1:
    d.reverse()
  elif A[i][1] == "1":
    d.appendleft(A[i][2])
  elif A[i][1] == "2":
    d.append(A[i][2])
print(''.join(d))

Fixed submission:
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
a = list(input())
Q = int(input())
B = []
C = []
A = [list(input().split()) for _ in range(Q)]
d = deque(a)
for i in range(len(A)):
  if len(A[i]) == 1:
    d.reverse()
  elif A[i][1] == "1":
    d.appendleft(A[i][2])
  elif A[i][1] == "2":
    d.append(A[i][2])
print(''.join(d))

Fixed submission:
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))

Buggy python submission (verdict: Time Limit Exceeded):
a = list(input())
Q = int(input())
B = []
C = []
A = [list(input().split()) for _ in range(Q)]
for i in range(len(A)):
  if len(A[i]) == 1:
    a.reverse()
  elif A[i][1] == "1":
    a.insert(0,A[i][2])
  elif A[i][1] == "2":
    a.append(A[i][2])
print(''.join(a))

Fixed submission:
from collections import deque
a = list(input())
Q = int(input())
d = deque(a)
ans = 1
for i in range(Q):
  b = list(input().split())
  if len(b) == 1:
    ans += 1
  elif b[1] == "1" and ans % 2 == 1:
    d.appendleft(b[2])
  elif b[1] == "1" and ans % 2 == 0:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 1:
    d.append(b[2])
  elif b[1] == "2" and ans % 2 == 0:
    d.appendleft(b[2])
if ans % 2 == 0:
  d.reverse()
print("".join(d))