Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
query = [0]
w = True
for i in range(q):
    query = list(map(str,input().split()))
    if(query[0] == "1"):
        w = not(w)
    else:
        mem = query[2]
        if(query[1] == "1"):
            if(w):
                s = mem + s
            else:
                s = s + mem
        else:
            if(w):
                s = s + mem
            else:
                s = mem + s
if(w):
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque
s = str(input())
q = int(input())
s = deque(s)
query = []
w = True
for i in range(q):
    query = list(map(str,input().split()))
    if(query[0] == "1"):
        w = not(w)
    else:
        mem = query[2]
        if(query[1] == "1"):
            if(w):
                s.appendleft(mem)
            else:
                s.append(mem)
        else:
            if(w):
                s.append(mem)
            else:
                s.appendleft(mem)
if(w):
    print("".join(s))
else:
    s.reverse()
    print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
query = [0 for _ in range(q)]
w = True
for i in range(q):
    query[i] = list(map(str,input().split()))
for i in range(q):
    if(query[i][0] == "1"):
        w = not(w)
    else:
        mem = query[i][2]
        if(query[i][1] == "1"):
            if(w):
                s = mem + s
            else:
                s = s + mem
        else:
            if(w):
                s = s + mem
            else:
                s = mem + s
if(w):
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque
s = str(input())
q = int(input())
s = deque(s)
query = []
w = True
for i in range(q):
    query = list(map(str,input().split()))
    if(query[0] == "1"):
        w = not(w)
    else:
        mem = query[2]
        if(query[1] == "1"):
            if(w):
                s.appendleft(mem)
            else:
                s.append(mem)
        else:
            if(w):
                s.append(mem)
            else:
                s.appendleft(mem)
if(w):
    print("".join(s))
else:
    s.reverse()
    print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())
query = [0 for _ in range(q)]
for i in range(q):
    query[i] = list(map(str,input().split()))
for i in range(q):
    if(query[i][0] == "1"):
        s = s[::-1]
    else:
        mem = query[i][2]
        if(query[i][1] == "1"):
            s = mem + s
        else:
            s = s + mem
print(s)

Fixed submission:
from collections import deque
s = str(input())
q = int(input())
s = deque(s)
query = []
w = True
for i in range(q):
    query = list(map(str,input().split()))
    if(query[0] == "1"):
        w = not(w)
    else:
        mem = query[2]
        if(query[1] == "1"):
            if(w):
                s.appendleft(mem)
            else:
                s.append(mem)
        else:
            if(w):
                s.append(mem)
            else:
                s.appendleft(mem)
if(w):
    print("".join(s))
else:
    s.reverse()
    print("".join(s))