Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

count = 0
top = bottom = ""

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    count = (count + 1) % 2  
  if query[0] == "2":    
    if query[1] == "1":      
      if count == 0:        
        top += query[2]       
      else:
        bottom += query[2]
    if query[1] == "2":      
      if count == 0:        
        bottom += query[2]        
      else:       
        top += query[2]
  
s = top[::-1] + s + bottom

if count == 1:  
  s = s[::-1]
  
print(s)

Fixed submission:
s = input()
q = int(input())

count = 0
top = []
bottom = []

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    count = (count + 1) % 2  
  if query[0] == "2":    
    if query[1] == "1":      
      if count == 0:        
        top.append(query[2])    
      else:
        bottom.append(query[2])
    if query[1] == "2":      
      if count == 0:        
        bottom.append(query[2])        
      else:       
        top.append(query[2])
  
t = "".join(top)
b = "".join(bottom)

lst = [t[::-1], s, b]
ans = "".join(lst)

if count == 1:
  ans = ans[::-1]
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

count = 0
for i in range(q):
  query = list(input().split())
  
  if query[0] == "1":
    count = (count + 1) % 2
    
  if query[0] == "2":
    
    if query[1] == "1":
      
      if count == 0:
        
        s = query[2] + s
        
      else:
        s = s + query[2]
    if query[1] == "2":
      
      if count == 0:
        
        s = s + query[2]
        
      else:
        
        s = query[2] + s

if count == 1:
  
  s = s[::-1]
  
print(s)

Fixed submission:
s = input()
q = int(input())

count = 0
top = []
bottom = []

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    count = (count + 1) % 2  
  if query[0] == "2":    
    if query[1] == "1":      
      if count == 0:        
        top.append(query[2])    
      else:
        bottom.append(query[2])
    if query[1] == "2":      
      if count == 0:        
        bottom.append(query[2])        
      else:       
        top.append(query[2])
  
t = "".join(top)
b = "".join(bottom)

lst = [t[::-1], s, b]
ans = "".join(lst)

if count == 1:
  ans = ans[::-1]
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

count = 0
for i in range(q):
  query = list(input().split())
  
  if query[0] == "1":
    count = (count + 1) % 2
    
  if query[0] == "2":
    
    if query[1] == "1":
      
      if count == 0:
        
        s = query[2] + s
        
      else:
        s = s + query[2]
    if query[1] == "2":
      
      if count == 0:
        
        s = s + query[2]
        
      else:
        
        s = query[2] + s

if count == 1:
  
  s = s[::-1]
  
print(s)

Fixed submission:
s = input()
q = int(input())

count = 0
top = []
bottom = []

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    count = (count + 1) % 2  
  if query[0] == "2":    
    if query[1] == "1":      
      if count == 0:        
        top.append(query[2])    
      else:
        bottom.append(query[2])
    if query[1] == "2":      
      if count == 0:        
        bottom.append(query[2])        
      else:       
        top.append(query[2])
  
t = "".join(top)
b = "".join(bottom)

lst = [t[::-1], s, b]
ans = "".join(lst)

if count == 1:
  ans = ans[::-1]
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    s = s[::-1]
  if query[0] == "2":
    if query[1] == "1":
      s = query[2] + s
    if query[1] == "2":
      s = s + query[2]
      
print(s)

Fixed submission:
s = input()
q = int(input())

count = 0
top = []
bottom = []

for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    count = (count + 1) % 2  
  if query[0] == "2":    
    if query[1] == "1":      
      if count == 0:        
        top.append(query[2])    
      else:
        bottom.append(query[2])
    if query[1] == "2":      
      if count == 0:        
        bottom.append(query[2])        
      else:       
        top.append(query[2])
  
t = "".join(top)
b = "".join(bottom)

lst = [t[::-1], s, b]
ans = "".join(lst)

if count == 1:
  ans = ans[::-1]
  
print(ans)