Buggy python submission (verdict: Time Limit Exceeded):

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = True
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if mode:
            if int(qs[2]) == 1:
                s = qs[4] + s
            else:
                s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                s = s + qs[4]
            else:
                s = qs[4] + s
        
#print(mode)
if not mode:
    s = s[::-1]



#for i in range(n):
#    print(qt[i],qf[i],qc[i])

print(s)

Fixed submission:

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = False
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

front = ''
back = ''
for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if not mode:
            if int(qs[2]) == 1:
                front += qs[4]
                #s = qs[4] + s
            else:
                back += qs[4]
                #s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                back += qs[4]
                #s = s + qs[4]
            else:
                front += qs[4]
                #s = qs[4] + s


#print(mode,front,back)
#hanten
if mode:
    print(back[::-1] + s[::-1] + front)
#no hanten
else:
    print(front[::-1] + s + back)

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

mode = True
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
    else:
        if mode:
            if int(qs[1:-2]) == 1:
                s = qs[-1] + s
            else:
                s = s + qs[-1]
        else:
            if int(qs[1:-2]) == 1:
                s = s + qs[-1]
            else:
                s = qs[-1] + s
        
#print(mode)
if not mode:
    s = s[::-1]

print(s)

Fixed submission:

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = False
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

front = ''
back = ''
for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if not mode:
            if int(qs[2]) == 1:
                front += qs[4]
                #s = qs[4] + s
            else:
                back += qs[4]
                #s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                back += qs[4]
                #s = s + qs[4]
            else:
                front += qs[4]
                #s = qs[4] + s


#print(mode,front,back)
#hanten
if mode:
    print(back[::-1] + s[::-1] + front)
#no hanten
else:
    print(front[::-1] + s + back)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
for i in range(n):
    qs = input()
    if len(qs) == 1:
        s = s[::-1]
    else:
        if int(qs[1:-2]) == 1:
            s = qs[-1] + s
        else:
            s = s + qs[-1]

print(s)

Fixed submission:

#import numpy as np
s = input()
n = int(input())
#qt = np.ones((n),dtype=np.int32)
#qf = np.zeros((n),dtype=np.int64)
#qc = [''] * n

mode = False
#mode = True : f1->s=c+s,f2->s=s+c
#mode = False : f1->s=s+c,f2->s=c+s

front = ''
back = ''
for i in range(n):
    qs = input()
    if len(qs) == 1:
        mode = not mode
        #s = s[::-1]
        #pass
    else:
        #qt[i] = 2
        #qf[i] = int(qs[1:-2])
        #qc[i] = qs[-1]
        if not mode:
            if int(qs[2]) == 1:
                front += qs[4]
                #s = qs[4] + s
            else:
                back += qs[4]
                #s = s + qs[4]
        else:
            if int(qs[2]) == 1:
                back += qs[4]
                #s = s + qs[4]
            else:
                front += qs[4]
                #s = qs[4] + s


#print(mode,front,back)
#hanten
if mode:
    print(back[::-1] + s[::-1] + front)
#no hanten
else:
    print(front[::-1] + s + back)