Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = [list(input().replace(' ','')) for _ in range(q)]

r = False
for i in range(q):
    if r:
        if len(query[i]) == 1:
            r = False
        elif query[i][1] == '1':
            s = s + query[i][2]
        else:
            s = query[i][2] + s
    else:
        if len(query[i]) == 1:
            r = True
        elif query[i][1] == '1':
            s = query[i][2] + s
        else:
            s = s + query[i][2]

if r:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.appendleft(i[2])
        else:
            if i[1] == '1':
                s.appendleft(i[2])
            else:
                s.append(i[2])
if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    s = ''.join(s)
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = [list(input().replace(' ','')) for _ in range(q)]

r = False
for i in range(q):
    if r:
        if len(query[i]) == 1:
            r = False
        elif query[i][1] == '1':
            s = s + query[i][2]
        else:
            s = query[i][2] + s
    else:
        if len(query[i]) == 1:
            r = True
        elif query[i][1] == '1':
            s = query[i][2] + s
        else:
            s = s + query[i][2]

if r:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.appendleft(i[2])
        else:
            if i[1] == '1':
                s.appendleft(i[2])
            else:
                s.append(i[2])
if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    s = ''.join(s)
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if i[0] == '1':
        if reverse:
            reverse = False
        else:
            reverse = True
        continue
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.insert(0,i[2])
        else:
            if i[1] == '1':
                s.insert(0,i[2])
            else:
                s.append(i[2])

if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    print(''.join(s))

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.appendleft(i[2])
        else:
            if i[1] == '1':
                s.appendleft(i[2])
            else:
                s.append(i[2])
if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    s = ''.join(s)
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s = s + i[2]
            else:
                s = i[2] + s
        else:
            if i[1] == '1':
                s = i[2] + s
            else:
                s = s + i[2]
if reverse:
    print(s[::-1])
else:
    print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.appendleft(i[2])
        else:
            if i[1] == '1':
                s.appendleft(i[2])
            else:
                s.append(i[2])
if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    s = ''.join(s)
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = [input().split() for _ in range(q)]

for i in query:
    if len(i) == 1:
        s = s[::-1]
    else:
        if i[1] == '1':
            s = i[2] + s
        if i[1] == '2':
            s = s + i[2]

print(s)


Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.appendleft(i[2])
        else:
            if i[1] == '1':
                s.appendleft(i[2])
            else:
                s.append(i[2])
if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    s = ''.join(s)
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = [input().split() for _ in range(q)]

for i in query:
    if len(i) == 1:
        s = s[::-1]
    else:
        if i[1] == '1':
            s = i[2] + s
        if i[1] == '2':
            s = s + i[2]

print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
query = [input().split() for _ in range(q)]

reverse = False
for i in query:
    if len(i) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if reverse:
            if i[1] == '1':
                s.append(i[2])
            else:
                s.appendleft(i[2])
        else:
            if i[1] == '1':
                s.appendleft(i[2])
            else:
                s.append(i[2])
if reverse:
    s = reversed(s)
    s = ''.join(s)
    print(s)
else:
    s = ''.join(s)
    print(s)