Buggy python submission (verdict: Runtime Error):
from collections import deque

z=list(input())
Q=deque()
Q.append((z))
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Fixed submission:
from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Buggy python submission (verdict: Runtime Error):
from collections import deque

z=list(input())
Q=deque()
Q.append(z)
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

Fixed submission:
from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

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

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      s.insert(0,x[4])
      
    else:
      s+=x[4]
      
if cnt%2==1:
  s.reverse()
  

print(''.join(s))
    

Fixed submission:
from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

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

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      s.insert(0,x[4])
      
    else:
      s+=x[4]
      
if cnt%2==1:
  s.reverse()
  

print(''.join(s))
    

Fixed submission:
from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

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

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      s=x[4]+s
      
    else:
      s=s+x[4]
      
if cnt%2==1:
  s=s[::-1]
  

print(s)
    

Fixed submission:
from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

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

cnt=0

for i in range(q):
  x=input()
  if x=='1':
    cnt+=1
    
  elif x[0]=='2':
    if (x[2]=='1' and cnt%2==0) or (x[2]=='2' and cnt%2==1):
      s=x[4]+s
      
    else:
      s=s+x[4]
      
if cnt%2==1:
  s=s[::-1]
  

print(s)
    

Fixed submission:
from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))