Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            sque.appendleft(que[i][2])
        else:
            sque.append(que[i][2])
    else:
        sque.reverse()
print("".join(list(sque)))

Fixed submission:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    sque.reverse()
    print("".join(list(sque)))
else:
    print("".join(list(sque)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = []
for i in range(q):
    que.append(list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            sque.appendleft(que[i][2])
        else:
            sque.append(que[i][2])
    else:
        sque.reverse()
print("".join(list(sque)))

Fixed submission:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    sque.reverse()
    print("".join(list(sque)))
else:
    print("".join(list(sque)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
que = []
for i in range(q):
    que.append(list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            s = que[i][2] + s
        else:
            s += que[i][2]
    else:
        s = s[::-1]
print(s)

Fixed submission:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    sque.reverse()
    print("".join(list(sque)))
else:
    print("".join(list(sque)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
que = [0] * q
t = []
f = []
c = []
for i in range(q):
    que[i] = list(map(str,input().split()))
    if(len(que[i])==3):
        if que[i][1] == '1':
            s = que[i][2] + s
        else:
            s += que[i][2]
    else:
        s = s[::-1]
print(s)

Fixed submission:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    sque.reverse()
    print("".join(list(sque)))
else:
    print("".join(list(sque)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
que = [0] * q
t = []
f = []
c = []
for i in range(q):
    que[i] = list(map(str,input().split()))
    if(len(que[i])==3):
        t.append(que[i][0])
        f.append(que[i][1])
        c.append(que[i][2])
    else:
        t.append(que[i][0])
count = 0
for i in range(q):
    if t[i] == '1':
        s = s[::-1]
    else:
        if f[count] == '1':
            s = c[count] + s
            count += 1
        else:
            s += c[count]
            count += 1
print(s)

Fixed submission:
from collections import deque
s = input()
sque = deque(s)
q = int(input())
que = [0] * q
flg = False
for i in range(q):
    que[i] = (list(map(str,input().split())))
    if(len(que[i])==3):
        if que[i][1] == '1':
            if flg:
                sque.append(que[i][2])
            else:
                sque.appendleft(que[i][2])
        else:
            if flg:
                sque.appendleft(que[i][2])
            else:
                sque.append(que[i][2])
    else:
        if flg:
            flg = False
        else:
            flg = True
if flg:
    sque.reverse()
    print("".join(list(sque)))
else:
    print("".join(list(sque)))