Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

flag=0
for i in range(Q):
    #query[i]=input()
    b=input()

    if(len(b)==1):
        #S=S[::-1]
        flag+=1
    else:
        a=b.split(" ")
        if(flag==0):
            if(a[1]=="1"):
                S=a[2]+S
            else:
                S+=a[2]
        else:
            if(a[1]=="2"):
                S=a[2]+S
            else:
                S+=a[2]
                
    flag=flag%2

if(flag==1):
    S=S[::-1]
print(S)



Fixed submission:
S=input()
Q=int(input())

flag=0
forward=""
back=""
for i in range(Q):
    #query[i]=input()
    b=input()

    if(len(b)==1):
        #S=S[::-1]
        flag+=1
    else:
        a=b.split(" ")
        if(flag==0):
            if(a[1]=="1"):
                #S=a[2]+S
                forward=a[2]+forward
            else:
                #S+=a[2]
                back=back+a[2]
        else:
            if(a[1]=="1"):
                #S=a[2]+S
                back=back+a[2]
            else:
                #S+=a[2]
                forward=a[2]+forward
                
    flag=flag%2

S=forward+S+back
if(flag==1):
    S=S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

query=[""]*Q
for i in range(Q):
    query[i]=input()

#print(query)

#Q is length
flag=0
for i in query:
    
        a=i.split(" ")
        if(len(a)==1):
            #S=S[::-1]
            flag+=1
        else:
            if(flag==0):
                if(a[1]=="1"):
                    S=a[2]+S
                else:
                    S+=a[2]
            else:
                if(a[1]=="2"):
                    S=a[2]+S
                else:
                    S+=a[2]

        flag=flag%2

if(flag==1):
    S=S[::-1]
print(S)



Fixed submission:
S=input()
Q=int(input())

flag=0
forward=""
back=""
for i in range(Q):
    #query[i]=input()
    b=input()

    if(len(b)==1):
        #S=S[::-1]
        flag+=1
    else:
        a=b.split(" ")
        if(flag==0):
            if(a[1]=="1"):
                #S=a[2]+S
                forward=a[2]+forward
            else:
                #S+=a[2]
                back=back+a[2]
        else:
            if(a[1]=="1"):
                #S=a[2]+S
                back=back+a[2]
            else:
                #S+=a[2]
                forward=a[2]+forward
                
    flag=flag%2

S=forward+S+back
if(flag==1):
    S=S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

query=[""]*Q
for i in range(Q):
    query[i]=input()

#print(query)

#Q is length
count=0
while(count<Q):
    if(count==0 or count==Q-1):
        a=query[count].split(" ")
        if(len(a)==1):
            S=S[::-1]
        else:
            if(a[1]=="1"):
                S=a[2]+S
            else:
                S+=a[2]
    else:
        a=query[count].split(" ")
        if(len(query[count+1].split(" "))==1 and len(a)==1):
            count+=2
            continue
        elif(len(a)==1):
            S=S[::-1]
        else:
            if(a[1]=="1"):
                S=a[2]+S
            else:
                S+=a[2]
    count+=1
    
print(S)


Fixed submission:
S=input()
Q=int(input())

flag=0
forward=""
back=""
for i in range(Q):
    #query[i]=input()
    b=input()

    if(len(b)==1):
        #S=S[::-1]
        flag+=1
    else:
        a=b.split(" ")
        if(flag==0):
            if(a[1]=="1"):
                #S=a[2]+S
                forward=a[2]+forward
            else:
                #S+=a[2]
                back=back+a[2]
        else:
            if(a[1]=="1"):
                #S=a[2]+S
                back=back+a[2]
            else:
                #S+=a[2]
                forward=a[2]+forward
                
    flag=flag%2

S=forward+S+back
if(flag==1):
    S=S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

query=[""]*Q
for i in range(Q):
    query[i]=input()

#print(query)

for i in query:
    a=i.split(" ")
    if(len(a)==1):
        S=S[::-1]
    else:
        if(a[1]=="1"):
            S=a[2]+S
        else:
            S+=a[2]
print(S)


Fixed submission:
S=input()
Q=int(input())

flag=0
forward=""
back=""
for i in range(Q):
    #query[i]=input()
    b=input()

    if(len(b)==1):
        #S=S[::-1]
        flag+=1
    else:
        a=b.split(" ")
        if(flag==0):
            if(a[1]=="1"):
                #S=a[2]+S
                forward=a[2]+forward
            else:
                #S+=a[2]
                back=back+a[2]
        else:
            if(a[1]=="1"):
                #S=a[2]+S
                back=back+a[2]
            else:
                #S+=a[2]
                forward=a[2]+forward
                
    flag=flag%2

S=forward+S+back
if(flag==1):
    S=S[::-1]
print(S)