Buggy python submission (verdict: Runtime Error):
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
s = deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1] == '2':
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result = ''.join(s)
if cond == -1:
    result = result[::-1]
print(result)


Fixed submission:
from collections import deque
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
word = deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])
        else:
            if query[i][1] == '2':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])

result = ''.join(word)
if cond == -1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Runtime Error):
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1] == '2':
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result = ''.join(s)
if cond == -1:
    result = result[::-1]
print(result)


Fixed submission:
from collections import deque
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
word = deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])
        else:
            if query[i][1] == '2':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])

result = ''.join(word)
if cond == -1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1

for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                s = query[i][2] + s
            else:
                s = s + query[i][2]
        else:
            if query[i][1] == '2':
                s = query[i][2] + s
            else:
                s = s + query[i][2]
if cond == -1:
    s = s[::-1]
print(s)


Fixed submission:
from collections import deque
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
word = deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])
        else:
            if query[i][1] == '2':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])

result = ''.join(word)
if cond == -1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
counter = 0

for i in range(n):
    if query[i] == ['1']:
        counter += 1
        for j in range(n-(i+1)):
            if query[i+j+1] == ['1']:
                continue
            if query[i+j+1][1] == '2':
                query[i+j+1][1] = '1'
            else:
                query[i+j+1][1] = '2'
for i in range(n):
    if query[i] != ['1']:
        if query[i][1] == '1':
            s = query[i][2] + s
        else:
            s = s + query[i][2]
if counter%2 == 1:
    s = s[::-1]
print(s)


Fixed submission:
from collections import deque
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
word = deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])
        else:
            if query[i][1] == '2':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])

result = ''.join(word)
if cond == -1:
    result = result[::-1]
print(result)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
for i in range(n):
    if query[i] == ['1']:
        s = s[::-1]
    elif query[i][1] == '1':
        s = query[i][2] + s
    else:
        s = s + query[i][2]
print(s)


Fixed submission:
from collections import deque
s = input()
n = int(input())
query = []
for i in range(n):
    query.append(input().split())
cond = 1
word = deque(s)
for i in range(n):
    if query[i] == ['1']:
        cond *= -1
    else:
        if cond == 1:
            if query[i][1] == '1':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])
        else:
            if query[i][1] == '2':
                word.appendleft(query[i][2])
            else:
                word.append(query[i][2])

result = ''.join(word)
if cond == -1:
    result = result[::-1]
print(result)