Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

reverse = 0

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        S.insert(0, Query[i][2])
      else:
        S.append(Query[i][2])
    else:
      if reverse % 2 == 0:
        S.append(Query[i][2])
      else:
        S.insert(0, Query[i][2])
        
ans = ''
s = ''.join(S)
if reverse % 2 == 0:
  ans = s
else:
  ans = s[::-1]
  
print(ans)

Fixed submission:
S = input()
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

reverse = 0
b = []
a = []

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        b.append(Query[i][2])
      else:
        a.append(Query[i][2])
    else:
      if reverse % 2 == 0:
        a.append(Query[i][2])
      else:
        b.append(Query[i][2])
        
ans = ''
s = (''.join(b))[::-1] + S + ''.join(a)
if reverse % 2 == 0:
  ans = s
else:
  ans = s[::-1]
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

reverse = 0

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        S.insert(0, Query[i][2])
      else:
        S.append(Query[i][2])
    else:
      if reverse % 2 == 0:
        S.append(Query[i][2])
      else:
        S.insert(0, Query[i][2])
        
ans = ''
s = ''.join(S)
if reverse % 2 == 0:
  ans = s
else:
  ans = s[::-1]
  
print(ans)

Fixed submission:
S = input()
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

reverse = 0
b = []
a = []

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        b.append(Query[i][2])
      else:
        a.append(Query[i][2])
    else:
      if reverse % 2 == 0:
        a.append(Query[i][2])
      else:
        b.append(Query[i][2])
        
ans = ''
s = (''.join(b))[::-1] + S + ''.join(a)
if reverse % 2 == 0:
  ans = s
else:
  ans = s[::-1]
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

reverse = 0

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        S = Query[i][2] + S
      else:
        S = S + Query[i][2]
    else:
      if reverse % 2 == 0:
        S = S + Query[i][2]
      else:
        S = Query[i][2] + S
        
ans = ''
if reverse % 2 == 0:
  ans = S
else:
  ans = S[::-1]
  
print(ans)

Fixed submission:
S = input()
Q = int(input())
Query = [list(map(str, input().split())) for i in range(Q)]

reverse = 0
b = []
a = []

for i in range(Q):
  if len(Query[i]) == 1:
    reverse += 1
  else:
    if Query[i][1] == '1':
      if reverse % 2 == 0:
        b.append(Query[i][2])
      else:
        a.append(Query[i][2])
    else:
      if reverse % 2 == 0:
        a.append(Query[i][2])
      else:
        b.append(Query[i][2])
        
ans = ''
s = (''.join(b))[::-1] + S + ''.join(a)
if reverse % 2 == 0:
  ans = s
else:
  ans = s[::-1]
  
print(ans)