Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

s = input().rstrip()
n = int(input().rstrip())
q_list = [input().rstrip().split() for i in range(n)]
front = ''
back = ''
count = 1
for i in q_list:
    if i[0] == '1':
        count *= -1
    else:
        if i[1] == '1':
            if count == 1:
                front += i[2]
            else:
                back += i[2]
        else:
            if count == 1:
                back += i[2]
            else:
                front += i[2]
if count == 1:
    print(front[::-1] + s + back)
else:
    print(back[::-1] + s[::-1] + front)

Fixed submission:
from collections import deque

s = deque(input())
n = int(input())
q_list = [input().split() for i in range(n)]
count = 1
for i in q_list:
    if i[0] == '1':
        count *= -1
    else:
        if i[1] == '1':
            if count == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if count == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])
if count != 1:
    s.reverse()
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

s = input().rstrip()
n = int(input().rstrip())
front = ''
back = ''
count = 1
for i in range(n):
    q = input().rstrip().split()
    if q[0] == '1':
        count *= -1
    else:
        if q[1] == '1':
            if count == 1:
                front += q[2]
            else:
                back += q[2]
        else:
            if count == 1:
                back += q[2]
            else:
                front += q[2]
if count == 1:
    print(front[::-1] + s + back)
else:
    print(back[::-1] + s[::-1] + front)

Fixed submission:
from collections import deque

s = deque(input())
n = int(input())
q_list = [input().split() for i in range(n)]
count = 1
for i in q_list:
    if i[0] == '1':
        count *= -1
    else:
        if i[1] == '1':
            if count == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if count == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])
if count != 1:
    s.reverse()
print(*s, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == '1':
        s_new = ''
        for i in range(len(s)):
            s_new += s[len(s)-1-i]
        s = s_new
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
print(s)

Fixed submission:
from collections import deque

s = deque(input())
n = int(input())
q_list = [input().split() for i in range(n)]
count = 1
for i in q_list:
    if i[0] == '1':
        count *= -1
    else:
        if i[1] == '1':
            if count == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if count == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])
if count != 1:
    s.reverse()
print(*s, sep='')

Buggy python submission (verdict: Runtime Error):
s = input()
n = int(input())
for i in range(n):
    q = input().split()
    if q[0] == '1':
        if len(s) != 1:
            s_new = ''
            for i in range(len(s)):
                s_new += s[len(s)-1-i]
            s = s_new
        else:
            pass
    else:
        if q[1] == '1':
            s = q[2] + s
        else:
            s += q[2]
    print(s)
print(s)

Fixed submission:
from collections import deque

s = deque(input())
n = int(input())
q_list = [input().split() for i in range(n)]
count = 1
for i in q_list:
    if i[0] == '1':
        count *= -1
    else:
        if i[1] == '1':
            if count == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if count == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])
if count != 1:
    s.reverse()
print(*s, sep='')