Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

rev = False
li_str = [s]
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                li_str.append(q[2])
            else:
                q_str = deque(li_str)
                q_str.appendleft(q[2])
                li_str = list(q_str)
        else:
            if rev:
                q_str = deque(li_str)
                q_str.appendleft(q[2])
                li_str = list(q_str)
            else:
                li_str.append(q[2])
                
ans = ''.join(li_str)
if rev:
    ans = ans[::-1]
    
print(ans)

Fixed submission:
from collections import deque

s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

rev = False
q_str = deque([s])
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                q_str.append(q[2])
            else:
                q_str.appendleft(q[2])
        else:
            if rev:
                q_str.appendleft(q[2])
            else:
                q_str.append(q[2])

li_str = list(q_str)
ans = ''.join(li_str)
if rev:
    ans = ans[::-1]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

rev = False
li_str = [s]
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                li_str.append(q[2])
            else:
                li_str.insert(0, q[2])
        else:
            if rev:
                li_str.insert(0, q[2])
            else:
                li_str.append(q[2])
                
ans = ''.join(li_str)
if rev:
    ans = ans[::-1]
    
print(ans)

Fixed submission:
from collections import deque

s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

rev = False
q_str = deque([s])
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                q_str.append(q[2])
            else:
                q_str.appendleft(q[2])
        else:
            if rev:
                q_str.appendleft(q[2])
            else:
                q_str.append(q[2])

li_str = list(q_str)
ans = ''.join(li_str)
if rev:
    ans = ans[::-1]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

ans = s
rev = False
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                ans = ans + q[2]
            else:
                ans = q[2] + ans
        else:
            if rev:
                ans = q[2] + ans
            else:
                ans = ans + q[2]
if rev:
    ans = ans[::-1]
print(ans)

Fixed submission:
from collections import deque

s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

rev = False
q_str = deque([s])
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                q_str.append(q[2])
            else:
                q_str.appendleft(q[2])
        else:
            if rev:
                q_str.appendleft(q[2])
            else:
                q_str.append(q[2])

li_str = list(q_str)
ans = ''.join(li_str)
if rev:
    ans = ans[::-1]
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

ans = s
for q in li_q:
    if q[0] == '1':
        ans = ans[::-1]
    else:
        if q[1] == '1':
            ans = q[2] + ans
        else:
            ans = ans + q[2]

print(ans)

Fixed submission:
from collections import deque

s=input()
query=int(input())

li_q = []
for _ in range(query):
    li_q.append(input().split())

rev = False
q_str = deque([s])
for q in li_q:
    if q[0] == '1':
        rev = not rev
    else:
        if q[1] == '1':
            if rev:
                q_str.append(q[2])
            else:
                q_str.appendleft(q[2])
        else:
            if rev:
                q_str.appendleft(q[2])
            else:
                q_str.append(q[2])

li_str = list(q_str)
ans = ''.join(li_str)
if rev:
    ans = ans[::-1]
    
print(ans)