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

c = 0
for i in range(n):
    if q[i][0] == "1":
        c += 1
    if q[i][0] == "2":
        if q[i][1] == "1" and c % 2 == 0 or q[i][1] == "2" and c % 2 == 1:
            s.insert(0, q[i][2])
        elif q[i][1] == "2" and c % 2 == 0 or q[i][1] == "1" and c % 2 == 1 :
            s.append(q[i][2])

if c % 2 == 1:
    s = s[::-1] 

print("".join(s))


Fixed submission:
from collections import deque

d = deque(input())
q = int(input())

reverse = False

for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    else:
        if query[1] == '1':
            if reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            if reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if reverse:
    d = list(reversed(d))


print("".join(map(str, d)))

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

c = 0
for i in range(n):
    if q[i][0] == "1":
        c += 1
    if q[i][0] == "2":
        if q[i][1] == "1" and c % 2 == 0 or q[i][1] == "2" and c % 2 == 1:
            s.insert(0, q[i][2])
        elif q[i][1] == "2" and c % 2 == 0 or q[i][1] == "1" and c % 2 == 1 :
            s.append(q[i][2])

if c % 2 == 1:
    s = s[::-1] 

print("".join(s))


Fixed submission:
from collections import deque

d = deque(input())
q = int(input())

reverse = False

for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    else:
        if query[1] == '1':
            if reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            if reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if reverse:
    d = list(reversed(d))


print("".join(map(str, d)))

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

for i in range(n):
    if q[i][0] == "1":
        s = s[::-1]
    if q[i][0] == "2":
        if q[i][1] == "1":
            s.insert(0, q[i][2])
        elif q[i][1] == "2":
            s.append(q[i][2])

print("".join(s))


Fixed submission:
from collections import deque

d = deque(input())
q = int(input())

reverse = False

for _ in range(q):
    query = list(input().split())
    if query[0] == '1':
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    else:
        if query[1] == '1':
            if reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            if reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if reverse:
    d = list(reversed(d))


print("".join(map(str, d)))