Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

rev = 0
for_s = ''
rev_s = ''

out = ''
out += s
for q in q_list:
    if q[0] == '1':
        rev = 1 - rev
    elif q[1] == '1':
        if rev == 0:
            #rev_s += q[2]
            out = q[2] + out
        else:
            #for_s += q[2]
            out = out + q[2]
    else:
        if rev == 0:
            #for_s += q[2]
            out = out + q[2]
        else:
            #rev_s += q[2]
            out = q[2] + out

#if rev == 0:
#    out = rev_s[::-1] + s + for_s
#else:
#    out = for_s[::-1] + s + rev_s
if rev == 1:
    out = out[::-1]
print(out)

Fixed submission:
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

rev = 0
for_s = ''
rev_s = ''

out = ''
for q in q_list:
    if q[0] == '1':
        rev = 1 - rev
    elif q[1] == '1':
        if rev == 0:
            rev_s += q[2]
        else:
            for_s += q[2]
    else:
        if rev == 0:
            for_s += q[2]
        else:
            rev_s += q[2]

if rev == 0:
    out = rev_s[::-1] + s + for_s
else:
    out = for_s[::-1] + s[::-1] + rev_s
print(out)

Buggy python submission (verdict: Runtime Error):
import pandas as pd

s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]
df = pd.DataFrame( columns=['S', 'N'] )
df = df.append(pd.Series([s, 0], index=df.columns), ignore_index=True)
out = ''

for q in q_list:
    if q[0] == '1':
        df['N'] = len(df) - 1 - df['N']
    elif q[1] == '1':
        df['N'] = df['N'] + 1
        df = df.append(pd.Series([q[2], 0], index=df.columns), ignore_index=True)
    else:
        df = df.append(pd.Series([q[2], len(df) ], index=df.columns), ignore_index=True)

df_s = df.sort_values('N')
for x in df_s['S']:
    out += x
print(out)


Fixed submission:
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

rev = 0
for_s = ''
rev_s = ''

out = ''
for q in q_list:
    if q[0] == '1':
        rev = 1 - rev
    elif q[1] == '1':
        if rev == 0:
            rev_s += q[2]
        else:
            for_s += q[2]
    else:
        if rev == 0:
            for_s += q[2]
        else:
            rev_s += q[2]

if rev == 0:
    out = rev_s[::-1] + s + for_s
else:
    out = for_s[::-1] + s[::-1] + rev_s
print(out)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

for q in q_list:
    if q[0] == '1':
        s = s[::-1]
    elif q[1] == '1':
        s = q[2] + s
    else:
        s = s + q[2]
print(s)


Fixed submission:
s = str(input())
n = int(input())
q_list = [list(map(str, input().strip().split())) for i in range(n)]

rev = 0
for_s = ''
rev_s = ''

out = ''
for q in q_list:
    if q[0] == '1':
        rev = 1 - rev
    elif q[1] == '1':
        if rev == 0:
            rev_s += q[2]
        else:
            for_s += q[2]
    else:
        if rev == 0:
            for_s += q[2]
        else:
            rev_s += q[2]

if rev == 0:
    out = rev_s[::-1] + s + for_s
else:
    out = for_s[::-1] + s[::-1] + rev_s
print(out)