Buggy python submission (verdict: Time Limit Exceeded):
s=input()
count_1=0
num =int(input())


for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s=i[2]+s
   
    elif i[1]=="1" and count_1%2==1:
        s=s+i[2]

    elif i[1]=="2" and count_1%2==0:
        s=s+i[2]

    elif i[1]=="2" and count_1%2==1:
        s=i[2]+s

if count_1%2==1:
    s=s[::-1]
print(s)

Fixed submission:
s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
count_1=0
num =int(input())


for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        continue
        
    elif i[1]=="1" and count_1%2==0:
        s=i[2]+s
        continue
   
    elif i[1]=="1" and count_1%2==1:
        s=s+i[2]
        continue

    elif i[1]=="2" and count_1%2==0:
        s=s+i[2]
        continue

    elif i[1]=="2" and count_1%2==1:
        s=i[2]+s
        continue
if count_1%2==1:
    s=s[::-1]
print(s)

Fixed submission:
s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
count_1=0
l=[]
num =int(input())


for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s=i[2]+s
   
    elif i[1]=="1" and count_1%2==1:
        s=s+i[2]

    elif i[1]=="2" and count_1%2==0:
        s=s+i[2]

    elif i[1]=="2" and count_1%2==1:
        s=i[2]+s

if count_1%2==1:
    s=s[::-1]
print(s)

Fixed submission:
s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
count_1=0
l=[]
num =int(input())
for i in range(num):
    q=input().rstrip().split()
    l.append(q)

for i in l:
    if i[0]=="1":
        s=s[::-1]
        
    elif i[1]=="1":
    
        s=i[2]+s
    elif i[1]=="2":
        s=s+i[2]
print(s)

Fixed submission:
s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
count_1=0
l=[]
num =int(input())
for i in range(num):
    q=input().rstrip().split()
    l.append(q)

for i in l:
    if i[0]=="1":
        s=s[::-1]
        
    else:
        if i[1]=="1":
            s=i[2]+s
        else:
            s=s+i[2]
print(s)

Fixed submission:
s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
num =int(input())
for i in range(num):
    q=input().rstrip().split()
    if q[0]=="1":
        s=s[::-1]
    else:
        if q[1]=="1":
            s=q[2]+s
        else:
            s=s+q[2]
print(s)

Fixed submission:
s=input()
s1=""
s2=""
count_1=0
l=[]
num =int(input())
 
 
for x in range(num):
    i=input().rstrip().split()
    if i[0]=="1":
        count_1+=1
        
    elif i[1]=="1" and count_1%2==0:
        s1=i[2]+s1
   
    elif i[1]=="1" and count_1%2==1:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==0:
        s2=s2+i[2]
 
    elif i[1]=="2" and count_1%2==1:
        s1=i[2]+s1
s=s1+s+s2
 
if count_1%2==1:
    s=s[::-1]
print(s)