Buggy python submission (verdict: Time Limit Exceeded):
S = input().rstrip()
Q = int(input().rstrip())
reversed = False
for _ in range(Q):
    l = input().rstrip()
    if l.startswith('1'):
        reversed = False if reversed else True
    else:
        _, F, C = l.split()
        if F == '1':
            if reversed:
                S = S + C
            else:
                S = C + S
        else:
            if reversed:
                S = C + S
            else:
                S = S + C
if reversed:
    ret = S[::-1]
else:
    ret = S
print(ret)


Fixed submission:
S = input().rstrip()
Q = int(input().rstrip())
reversed = False
from collections import deque
q = deque()
q.extend(list(S))
for _ in range(Q):
    l = input().rstrip()
    if l.startswith('1'):
        reversed = False if reversed else True
    else:
        _, F, C = l.split()
        if F == '1':
            if reversed:
                q.append(C)
            else:
                q.appendleft(C)
        elif F == '2':
            if reversed:
                q.appendleft(C)
            else:
                q.append(C)
ret = ''.join(list(q)[::-1]) if reversed else ''.join(list(q))
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
S = input().rstrip()
Q = int(input().rstrip())
reversed = False
for _ in range(Q):
    l = input().rstrip()
    if l.startswith('1'):
        reversed = False if reversed else True
    else:
        _, F, C = l.split()
        if F == '1':
            if reversed:
                S = S + C
            else:
                S = C + S
        else:
            if reversed:
                S = C + S
            else:
                S = S + C
if reversed:
    ret = S[::-1]
else:
    ret = S
print(ret)


Fixed submission:
S = input().rstrip()
Q = int(input().rstrip())
reversed = False
from collections import deque
q = deque()
q.extend(list(S))
for _ in range(Q):
    l = input().rstrip()
    if l.startswith('1'):
        reversed = False if reversed else True
    else:
        _, F, C = l.split()
        if F == '1':
            if reversed:
                q.append(C)
            else:
                q.appendleft(C)
        elif F == '2':
            if reversed:
                q.appendleft(C)
            else:
                q.append(C)
ret = ''.join(list(q)[::-1]) if reversed else ''.join(list(q))
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
S = input().rstrip()
Q = int(input().rstrip())
for _ in range(Q):
    l = input().rstrip()
    if l.startswith('1'):
        S = S[::-1]
    else:
        _, F, C = l.split()
        if F == '1':
            S = C + S
        else:
            S = S + C
print(S)


Fixed submission:
S = input().rstrip()
Q = int(input().rstrip())
reversed = False
from collections import deque
q = deque()
q.extend(list(S))
for _ in range(Q):
    l = input().rstrip()
    if l.startswith('1'):
        reversed = False if reversed else True
    else:
        _, F, C = l.split()
        if F == '1':
            if reversed:
                q.append(C)
            else:
                q.appendleft(C)
        elif F == '2':
            if reversed:
                q.appendleft(C)
            else:
                q.append(C)
ret = ''.join(list(q)[::-1]) if reversed else ''.join(list(q))
print(ret)