Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
a = 0
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      S = [q[2]] + S
    else:
      S = S + [q[2]]
if a == 1:
  S = S[::-1]
S = ''.join(S)
print(S)

Fixed submission:
S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
a = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    if (q[1] == '1' and a == 0) or (q[1] == '2' and a == 1):
      S = [q[2]] + S
    else:
      S = S + [q[2]]
if a == 1:
  S = S[::-1]
S = ''.join(S)
print(S)

Fixed submission:
S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
a = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    a += 1
  else:
    if (q[1] == '1' and a % 2 == 0) or (q[1] == '2' and a % 2 == 1):
      S = [q[2]] + S
    else:
      S = S + [q[2]]
if a % 2 == 1:
  S = S[::-1]
S = ''.join(S)
print(S)

Fixed submission:
S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
a = 0
b = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    b += 1
    
  elif (q[1] == '1' and b%2 == 0) or (q[1] == '2' and b%2 == 1):
    S= q[2]+S
    
    
  else:
    S = S+q[2]
    
if b%2 == 1 and len(S) > 1:
  S = S[::-1]
    

print(S)

Fixed submission:
S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
  q = list(input().split())
  if q[0] == '1' and len(S) > 1:
    S = S[::-1]
    
  elif q[1] == '1':
    S = [q[2]] + S
    
  else:
    S = S+[q[2]]
    
S="".join(S)
print(S)

Fixed submission:
S = list(input())
Q = int(input())
a = 0
A = []
B = []
for i in range(Q):
  q = list(input().split())
  q[0] = int(q[0])
  if q[0] == 1:
    if a == 0:
      a = 1
    else:
      a = 0
  else:
    q[1] = int(q[1])
    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
      B.append(q[2])
    else:
      A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
  ans = ans[::-1]
ans = ''.join(ans)
print(ans)