Buggy python submission (verdict: Time Limit Exceeded):
texts = str(input())
Q = int(input())


reverse = False
start_text = ''
end_text = ''
input_texts = []
for _ in range(Q):
    input_texts.append(list(input().split()))

for input_text in input_texts:
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text += str(input_text[2])
            else:
                start_text = str(input_text[2]) + start_text
        else:  # 末尾に
            if reverse:
                start_text = str(input_text[2]) + start_text
            else:
                end_text += str(input_text[2])

if reverse:
    texts = list(start_text + texts + end_text)
    texts.reverse()
    print("".join(texts))
else:
    # texts = start_text + texts + end_text
    print(start_text + texts + end_text)


Fixed submission:
from collections import deque
texts = deque(str(input()))
Q = int(input())


reverse = False
start_text = deque('')
end_text = deque('')
input_texts = []
for _ in range(Q):
    input_texts.append(list(input().split()))

for input_text in input_texts:
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text.append(str(input_text[2]))
            else:
                start_text.appendleft(str(input_text[2]))
        else:  # 末尾に
            if reverse:
                start_text.appendleft(input_text[2])
            else:
                end_text.append(input_text[2])

# print(start_text, texts, end_text)
# print(''.join(texts))

texts.appendleft(''.join(start_text))
texts.append(''.join(end_text))
# print(''.join(texts))

# print(texts)
if reverse:
    texts = deque("".join(texts))
    texts.reverse()
    print("".join(texts))
else:
    # texts = start_text + texts + end_text
    print(''.join(texts))

Buggy python submission (verdict: Time Limit Exceeded):
texts = str(input())
Q = int(input())


reverse = False
start_text = ''
end_text = ''
input_texts = []
for _ in range(Q):
    input_texts.append(list(input().split()))

for input_text in input_texts:
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text += str(input_text[2])
            else:
                start_text = str(input_text[2]) + start_text
        else:  # 末尾に
            if reverse:
                start_text = str(input_text[2]) + start_text
            else:
                end_text += str(input_text[2])

if reverse:
    text = ''.join(texts)
    text = list(start_text + text + end_text)
    text.reverse()
    print("".join(text))
else:
    text = ''.join(texts)
    text = start_text + text + end_text
    print(text)


Fixed submission:
from collections import deque
texts = deque(str(input()))
Q = int(input())


reverse = False
start_text = deque('')
end_text = deque('')
input_texts = []
for _ in range(Q):
    input_texts.append(list(input().split()))

for input_text in input_texts:
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text.append(str(input_text[2]))
            else:
                start_text.appendleft(str(input_text[2]))
        else:  # 末尾に
            if reverse:
                start_text.appendleft(input_text[2])
            else:
                end_text.append(input_text[2])

# print(start_text, texts, end_text)
# print(''.join(texts))

texts.appendleft(''.join(start_text))
texts.append(''.join(end_text))
# print(''.join(texts))

# print(texts)
if reverse:
    texts = deque("".join(texts))
    texts.reverse()
    print("".join(texts))
else:
    # texts = start_text + texts + end_text
    print(''.join(texts))

Buggy python submission (verdict: Time Limit Exceeded):
texts = str(input())
Q = int(input())


reverse = False
start_text = ''
end_text = ''
for _ in range(Q):
    input_text = list(input().split())
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text += str(input_text[2])
            else:
                start_text = str(input_text[2]) + start_text
        else:  # 末尾に
            if reverse:
                start_text = str(input_text[2]) + start_text
            else:
                end_text += str(input_text[2])

if reverse:
    text = ''.join(texts)
    text = start_text + text + end_text
    text = list(text)[::-1]
    print(''.join(text))
else:
    text = ''.join(texts)
    text = start_text + text + end_text
    print(text)


Fixed submission:
from collections import deque
texts = deque(str(input()))
Q = int(input())


reverse = False
start_text = deque('')
end_text = deque('')
input_texts = []
for _ in range(Q):
    input_texts.append(list(input().split()))

for input_text in input_texts:
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text.append(str(input_text[2]))
            else:
                start_text.appendleft(str(input_text[2]))
        else:  # 末尾に
            if reverse:
                start_text.appendleft(input_text[2])
            else:
                end_text.append(input_text[2])

# print(start_text, texts, end_text)
# print(''.join(texts))

texts.appendleft(''.join(start_text))
texts.append(''.join(end_text))
# print(''.join(texts))

# print(texts)
if reverse:
    texts = deque("".join(texts))
    texts.reverse()
    print("".join(texts))
else:
    # texts = start_text + texts + end_text
    print(''.join(texts))

Buggy python submission (verdict: Time Limit Exceeded):
texts = list(str(input()))
Q = int(input())


reverse = False

for _ in range(Q):
    input_text = list(input().split())
    if len(input_text) == 1:
        texts = texts[::-1]
    else:
        if input_text[1] == '1':
            texts.insert(0, input_text[2])
        else:
            texts.append(input_text[2])

print(''.join(texts))


Fixed submission:
from collections import deque
texts = deque(str(input()))
Q = int(input())


reverse = False
start_text = deque('')
end_text = deque('')
input_texts = []
for _ in range(Q):
    input_texts.append(list(input().split()))

for input_text in input_texts:
    if len(input_text) == 1:
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        if input_text[1] == '1':  # 先頭に
            if reverse:
                end_text.append(str(input_text[2]))
            else:
                start_text.appendleft(str(input_text[2]))
        else:  # 末尾に
            if reverse:
                start_text.appendleft(input_text[2])
            else:
                end_text.append(input_text[2])

# print(start_text, texts, end_text)
# print(''.join(texts))

texts.appendleft(''.join(start_text))
texts.append(''.join(end_text))
# print(''.join(texts))

# print(texts)
if reverse:
    texts = deque("".join(texts))
    texts.reverse()
    print("".join(texts))
else:
    # texts = start_text + texts + end_text
    print(''.join(texts))