Buggy python submission (verdict: Time Limit Exceeded):
import collections as co
S=input()
Q=int(input())
count=0
back=str()
front=str()
judge=True
for i in range(Q):
    a=list(map(str,input().split()))   
    if  int(a[0])==1:
        if judge==True:
            judge=False
        else:
            judge=True
    elif int(a[0])==2 and int(a[1])==1:
        if judge==True:
            front=a[2]+front
        if judge==False:
            back=back+a[2]
    else:
        if judge==True:
            back=back+a[2]
        if judge==False:
            front=a[2]+front
    a.clear
if judge==True:
    S=front+S+back
if judge==False:
    S=S[::-1]
    back=back[::-1]
    front=front[::-1]
    S=back+S+front
print(S)

Fixed submission:
import collections as co
S=input()
Q=int(input())
count=0
back=str()
front=str()
judge=True
for i in range(Q):
    a=list(map(str,input().split()))   
    if  int(a[0])==1:
        if judge==True:
            judge=False
        else:
            judge=True
    elif int(a[0])==2 and int(a[1])==1:
        if judge==True:
            front=a[2]+front
        if judge==False:
            back=back+a[2]
    else:
        if judge==True:
            back=back+a[2]
        if judge==False:
            front=a[2]+front
    a.clear
if judge==True:
    S=front+S+back
if judge==False:
    S=front+S+back
    S=S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
import collections as co
S=input()
Q=int(input())
count=0
back=str()
front=str()
for i in range(Q):
    a=list(map(str,input().split()))
    if  int(a[0])==1:
        count+=1
        back_front=front[::-1]
        front_back=back[::-1]
        back=back_front
        front=front_back
    elif int(a[0])!=1 and int(a[1])==1:
        front=a[2]+front
    elif int(a[0])!=1 and int(a[1])==2:
        back=back+a[2]
    a.clear
if count%2==1:
    S=S[::-1]
S=front+S+back
print(S)

Fixed submission:
import collections as co
S=input()
Q=int(input())
count=0
back=str()
front=str()
judge=True
for i in range(Q):
    a=list(map(str,input().split()))   
    if  int(a[0])==1:
        if judge==True:
            judge=False
        else:
            judge=True
    elif int(a[0])==2 and int(a[1])==1:
        if judge==True:
            front=a[2]+front
        if judge==False:
            back=back+a[2]
    else:
        if judge==True:
            back=back+a[2]
        if judge==False:
            front=a[2]+front
    a.clear
if judge==True:
    S=front+S+back
if judge==False:
    S=front+S+back
    S=S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for i in range(Q):
    a=list(map(str,input().split()))
    if  int(a[0])==1:
        S=S[::-1]
    elif int(a[0])!=1 and int(a[1])==1:
        S=a[2]+S
    elif int(a[0])!=1 and int(a[1])==2:
        S=S+a[2]
    a.clear
print(S)

Fixed submission:
import collections as co
S=input()
Q=int(input())
count=0
back=str()
front=str()
judge=True
for i in range(Q):
    a=list(map(str,input().split()))   
    if  int(a[0])==1:
        if judge==True:
            judge=False
        else:
            judge=True
    elif int(a[0])==2 and int(a[1])==1:
        if judge==True:
            front=a[2]+front
        if judge==False:
            back=back+a[2]
    else:
        if judge==True:
            back=back+a[2]
        if judge==False:
            front=a[2]+front
    a.clear
if judge==True:
    S=front+S+back
if judge==False:
    S=front+S+back
    S=S[::-1]
print(S)