Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if q[1] == "1":
            if flag:
                s = list(q[2])+s
            else:
                s = s+list(q[2])
        else:
            if flag:
                s = s+list(q[2])
            else:
                s = list(q[2])+s
if flag == False:
    s.reverse()
print("".join(s))

Fixed submission:
from collections import deque
s = deque(list(input()))
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if (q[1] == "1" and flag == False) or (q[1] == "2" and flag):
            s.append(q[2])
        else:
            s.appendleft(q[2])
if flag == False:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = int(input())
sl = []
fl = []
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if q[1] == "1":
            if flag:
                s = list(q[2])+s
            else:
                s = s+list(q[2])
        else:
            if flag:
                s = s+list(q[2])
            else:
                s = list(q[2])+s
if flag == False:
    s.reverse()
print("".join(s))

Fixed submission:
from collections import deque
s = deque(list(input()))
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if (q[1] == "1" and flag == False) or (q[1] == "2" and flag):
            s.append(q[2])
        else:
            s.appendleft(q[2])
if flag == False:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = int(input())
sl = []
fl = []
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if q[1] == "1":
            if flag:
                sl.insert(0, q[2])
            else:
                fl.append(q[2])
        else:
            if flag:
                fl.append(q[2])
            else:
                sl.insert(0, q[2])
if flag:
    s = sl+s
    s = s+fl
else:
    sl.reverse()
    fl.reverse()
    s.reverse()
    s = fl+s
    s = s+sl
print("".join(s))

Fixed submission:
from collections import deque
s = deque(list(input()))
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if (q[1] == "1" and flag == False) or (q[1] == "2" and flag):
            s.append(q[2])
        else:
            s.appendleft(q[2])
if flag == False:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = int(input())
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        s.reverse()
    if len(q) == 3:
        if q[1] == "1":
            s.insert(0, q[2])
        else:
            s.append(q[2])
print("".join(s))

Fixed submission:
from collections import deque
s = deque(list(input()))
n = int(input())
flag = True
for _ in range(n):
    q = list(map(str, input().split()))
    if len(q) == 1:
        if flag:
            flag = False
        else:
            flag = True
    if len(q) == 3:
        if (q[1] == "1" and flag == False) or (q[1] == "2" and flag):
            s.append(q[2])
        else:
            s.appendleft(q[2])
if flag == False:
    s.reverse()
print("".join(s))