Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

s = input().strip()
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        a=int(a)
        if count&1==1:
            b=3-b
        if int(b)==2:
            s+=c
        else:
            v = list(s)
            v.insert(0,c)
            s = "".join(v)
if count &1==1:
    s=s[::-1]
print(s)
            
            



Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

s = deque(input().strip())
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        if count&1==1:
            b=3-b
        if b==2:
            s.append(c)
        else:
            s.appendleft(c)
if count&1==1:
    print("".join(list(s)[::-1])) 
else:
    print("".join(s))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

s = list(input().strip())
q=int(input())
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        s.reverse()
    else:
        a,b,c = L
        if int(b)==2:
            s.append(c)
        else:
            s.insert(0,c)
            s = "".join(s)
print(s)
            
            


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

s = deque(input().strip())
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        if count&1==1:
            b=3-b
        if b==2:
            s.append(c)
        else:
            s.appendleft(c)
if count&1==1:
    print("".join(list(s)[::-1])) 
else:
    print("".join(s))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

s = list(input().strip())
q=int(input())
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        s.reverse
    else:
        a,b,c = L
        if int(b)==2:
            s.append(c)
        else:
            s.insert(0,c)
            s = "".join(s)
print(s)
            
            


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

s = deque(input().strip())
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        if count&1==1:
            b=3-b
        if b==2:
            s.append(c)
        else:
            s.appendleft(c)
if count&1==1:
    print("".join(list(s)[::-1])) 
else:
    print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

s = input().strip()
q=int(input())
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        s = s[::-1]
    else:
        a,b,c = L
        if int(b)==2:
            s+=c
        else:
            v = list(s)
            v.insert(0,c)
            s = "".join(v)
print(s)
            
            


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

s = deque(input().strip())
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        if count&1==1:
            b=3-b
        if b==2:
            s.append(c)
        else:
            s.appendleft(c)
if count&1==1:
    print("".join(list(s)[::-1])) 
else:
    print("".join(s))