Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S = q[4]+S
        else:
            S = S+q[4]
    else:
        s *= -1
if s==1:
    print(S)
else:
    print(S[::-1])

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S.extendleft(q[4])
        else:
            S.extend(q[4])
    else:
        s *= -1
S = ''.join(list(S))
if s==1:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = raw_input()
Q = int(raw_input())
for _ in range(Q):
    q = raw_input()
    if q!='1':
        if q[2]=='1':
            S = q[4]+S
        else:
            S = S+q[4]
    else:
        S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S.extendleft(q[4])
        else:
            S.extend(q[4])
    else:
        s *= -1
S = ''.join(list(S))
if s==1:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    q = input()
    if q!='1':
        tmp = []
        if q[2]=='1':
            tmp.append(q[4])
            tmp.append(S)
        else:
            tmp.append(S)
            tmp.append(q[4])
        S = ''.join(tmp)
    else:
        S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S.extendleft(q[4])
        else:
            S.extend(q[4])
    else:
        s *= -1
S = ''.join(list(S))
if s==1:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    q = input()
    if len(q)>1:
        _, f, c = q.split()
        if f=='1':
            S = c+S
        else:
            S = S+c
    else:
        S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S.extendleft(q[4])
        else:
            S.extend(q[4])
    else:
        s *= -1
S = ''.join(list(S))
if s==1:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    q = input()
    if len(q)>1:
        _, f, c = q.split()
        f = int(f)
        if f==1:
            S = c+S
        else:
            S = S+c
    else:
        S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S.extendleft(q[4])
        else:
            S.extend(q[4])
    else:
        s *= -1
S = ''.join(list(S))
if s==1:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    q = input()
    if len(q)>1:
        _, f, c = q.split()
        f = int(f)
        if f==1:
            S = c+S
        else:
            S = S+c
    else:
        S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
s = 1
for _ in range(Q):
    q = input()
    if q!='1':
        if (q[2]=='1' and s==1) or (q[2]!='1' and s!=1):
            S.extendleft(q[4])
        else:
            S.extend(q[4])
    else:
        s *= -1
S = ''.join(list(S))
if s==1:
    print(S)
else:
    print(S[::-1])