Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

revFlag = False
s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
    else:
        if(revFlag):
            s.reverse()
            revFlag = False
        
        if(b == '1'):
            s.appendleft(c)
        else:
            s.append(c)

if(revFlag):
    s.reverse()
    
print(*s, sep='')


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        s.reverse()
    else:
        if(b == '1'):
            s.appendleft(c)
        else:
            s.append(c)

print(*s, sep='')


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

reflag = 0
s = deque(input())
q = int(input())

for _ in range(q):
    x = input().split()
    
    if(x[0]=='1'):
        reflag = reflag + 1
        #s.reverse()
    else:
        if(reflag % 2 == 0):
            reflag = 0
        else:
            s.reverse()
            reflag = 0
        
        s.appendleft(x[2]) if(x[1]=='1') else s.append(x[2])

if(reflag % 2 == 0):
    pass
else:
    s.reverse()

print(''.join(s))


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = deque(input())
q = int(input())

for _ in range(q):
    x = input().split()
    
    if(x[0]=='1'):
        s.reverse()
    else:
        s.appendleft(x[2]) if(x[1]=='1') else s.append(x[2])

print(''.join(s))


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
rflag = 0
s = [i for i in input()]
q = int(input())

for i in range(q):
    x = input().split()
    
    if(x[0] == '1'):
        rflag = rflag + 1
        # s = s[::-1]
    else:
        if((rflag % 2) == 0):
            rflag = 0
        else:
            s = s[::-1]
            rflag = 0
            
        s.insert(0,x[2]) if(x[1]=='1') else s.append(x[2])

s = s if((rflag % 2) == 0) else s[::-1]

print(''.join(s))


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Runtime Error):
rflag = 0
s = [i for i in input()]
q = int(input())

for i in range(q):
    x = input().split()
    
    if(x[0] == '1'):
        rflag = rflag + 1
        # s = s[::-1]
    else:
        if((rflag % 2) == 0):
            rflag = 0
        else:
            s = s[::-1]
            rflag = 0
            
        s.insert(0,x[2]) if(x[1]=='1') else s.append(x[2])

s if((rflag % 2) == 0) else s = s[::-1]

print(''.join(s))


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
s = [i for i in input()]
q = int(input())

for i in range(q):
    x = input().split()
    
    if(x[0] == '1'):
        s = s[::-1]
    else:
        s.insert(0,x[2]) if(x[1]=='1') else s.append(x[2])


print(''.join(s))

Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
def sr(x):
    y = ''
    for i in range(len(x)-1,-1,-1):
        y = '%s%s' %(y,x[i])
    return y

s = input()
q = int(input())

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        #s = s[::-1]
        s = sr(s)
    else:
        s = '%s%s'%(x[2],s) if (x[1] == '1') else '%s%s'%(s,x[2])

print(s)


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

Buggy python submission (verdict: Runtime Error):
def sr(x):
    y = ''
    for i in range(len(x)-1,-1,-1):
        y = '%s%s' %(y,x[i])
        print(y)
    print(y)    
    return y

s = input()
q = int(input())

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        #s = s[::-1]
        s = sr(s)
    else:
        s = '%s%s'%(x[2],s) if (x[1] == '1') else '%s%s'%(s,x[2])

print(s)


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

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

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        s = s[::-1]
    else:
        s = '%s%s'%(x[2],s) if (x[1] == '1') else '%s%s'%(s,x[2])
        '''
        if(x[1] == '1'):
            s = x[2] + s
        else:
            s += x[2]
        '''
print(s)


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

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

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        s = s[::-1]
    else:
        s = x[2]+s if (x[1] == '1') else s + x[2]
        '''
        if(x[1] == '1'):
            s = x[2] + s
        else:
            s += x[2]
        '''
print(s)

Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

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

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        s = s[::-1]
    else:
        if(x[1] == '1'):
            s = x[2] + s
        else:
            s += x[2]
print(s)

Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

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

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        rflag += 1
        # s = s[::-1]
    elif(x[0] == '2'):
        if((rflag % 2) == 0):
            rflag = 0
        else:
            s = s[::-1]
            rflag = 0
        
        if(x[1] == '1'):
            s = x[2] + s
        elif(x[1] == '2'):
            s += x[2]
if(rflag % 2 == 0):
    pass
else:
    s = s[::-1]

print(s)


Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')

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

for i in range(q):
    x = input().split()
    
    if (x[0] == '1'):
        s = s[::-1]
    elif(x[0] == '2'):
        if(x[1] == '1'):
            s = x[2] + s
        elif(x[1] == '2'):
            s += x[2]

print(s)

Fixed submission:
from collections import deque

revFlag = False

s = deque(input())
q = int(input())

for i in range(q):
    a,b,c, *_ = input().split() + [None, None]
    
    if(a == '1'):
        revFlag = not revFlag
        
    else:
        b = int(b)
        if(revFlag):
            b = (int(b)%2)+1
        
        if(b == 1):
            s.appendleft(c)
        else:
            s.append(c)
            
    #print(_,*s, sep="")

if(revFlag):
    s.reverse()
    
print(*s, sep='')