Buggy python submission (verdict: Time Limit Exceeded):
string=list(input())
Q=int(input())
reverse=0
def func1(s):
    s.reverse()
    
def func2(s,F,C):
    if F=="1":
        s.insert(0,C)
        #return s
    if F=="2":
        s.append(C)
        #return s

            
for i in range(Q):
    Input=list(map(str,input().split()))
    if Input[0]=='1':
        func1(string)
        
    elif Input[0]=='2':
        func2(string,Input[1],Input[2])
for i in string:
    print(i,end="")

Fixed submission:
S = str(input())
Q = int(input())
 
hanten = 0
front = ""
end = ""
 
for i in range(Q):
    query=list(map(str,input().split()))
    if query[0]=="1":
        hanten+=1
        hanten=hanten%2
    else:
        if query[1]=="1":
            if hanten==0:
                front=query[2]+front
            else:
                end=end+query[2]
        else:
            if hanten==0:
                end=end+query[2]
            else:
                front=query[2]+front
ans=front+S+end
if hanten==1:
    ans=ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
string=list(input())
Q=int(input())
def func1(s):
    s.reverse()
    
def func2(s,F,C):
    if F=="1":
        s.insert(0,C)
        #return s
    if F=="2":
        s.append(C)
        #return s

            
for i in range(Q):
    Input=list(map(str,input().split()))
    if Input[0]=='1':
        func1(string)
        
    elif Input[0]=='2':
        func2(string,Input[1],Input[2])
for i in string:
    print(i,end="")

Fixed submission:
S = str(input())
Q = int(input())
 
hanten = 0
front = ""
end = ""
 
for i in range(Q):
    query=list(map(str,input().split()))
    if query[0]=="1":
        hanten+=1
        hanten=hanten%2
    else:
        if query[1]=="1":
            if hanten==0:
                front=query[2]+front
            else:
                end=end+query[2]
        else:
            if hanten==0:
                end=end+query[2]
            else:
                front=query[2]+front
ans=front+S+end
if hanten==1:
    ans=ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
string=list(input())
Q=int(input())
def func1(s):
    s.reverse()
    return s
def func2(s,F,C):
    if F=="1":
        s.insert(0,C)
        #return s
    if F=="2":
        s.append(C)
        #return s

            
for i in range(Q):
    Input=list(map(str,input().split()))
    if Input[0]=='1':
        func1(string)
        
    elif Input[0]=='2':
        func2(string,Input[1],Input[2])
for i in string:
    print(i,end="")

Fixed submission:
S = str(input())
Q = int(input())
 
hanten = 0
front = ""
end = ""
 
for i in range(Q):
    query=list(map(str,input().split()))
    if query[0]=="1":
        hanten+=1
        hanten=hanten%2
    else:
        if query[1]=="1":
            if hanten==0:
                front=query[2]+front
            else:
                end=end+query[2]
        else:
            if hanten==0:
                end=end+query[2]
            else:
                front=query[2]+front
ans=front+S+end
if hanten==1:
    ans=ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
string=str(input())
Q=int(input())
def func1(s):
    s=s[::-1]
    return s
def func2(s,F,C):
    if F=="1":
        s=C+s
        return s
    if F=="2":
        s=s+C
        return s

            
for i in range(Q):
    Input=list(map(str,input().split()))
    if Input[0]=='1':
        string=func1(string)
        
    elif Input[0]=='2':
        string=func2(string,Input[1],Input[2])

print(string)            
        
        

Fixed submission:
S = str(input())
Q = int(input())
 
hanten = 0
front = ""
end = ""
 
for i in range(Q):
    query=list(map(str,input().split()))
    if query[0]=="1":
        hanten+=1
        hanten=hanten%2
    else:
        if query[1]=="1":
            if hanten==0:
                front=query[2]+front
            else:
                end=end+query[2]
        else:
            if hanten==0:
                end=end+query[2]
            else:
                front=query[2]+front
ans=front+S+end
if hanten==1:
    ans=ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
string=str(input())
Q=int(input())
def func1(s):
    s=s[::-1]
    return s
def func2(s,F,C):
    if F=="1":
        s=C+s
        return s
    if F=="2":
        s=s+C
        return s

            
for i in range(Q):
    Input=list(map(str,input().split()))
    if Input[0]=='1':
        string=func1(string)
        
    elif Input[0]=='2':
        string=func2(string,Input[1],Input[2])

print(string)            
        
        

Fixed submission:
S = str(input())
Q = int(input())
 
hanten = 0
front = ""
end = ""
 
for i in range(Q):
    query=list(map(str,input().split()))
    if query[0]=="1":
        hanten+=1
        hanten=hanten%2
    else:
        if query[1]=="1":
            if hanten==0:
                front=query[2]+front
            else:
                end=end+query[2]
        else:
            if hanten==0:
                end=end+query[2]
            else:
                front=query[2]+front
ans=front+S+end
if hanten==1:
    ans=ans[::-1]
print(ans)