Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())
 
from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])
 
check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1
 
if check % 2 == 1:
    S_list = list(reversed(S_list))
 
str_list = deque()
str_list.append(S)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))

Fixed submission:
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

S_list = [i for i in S]
if check % 2 == 1:
    S_list = list(reversed(S_list))

S_n = ''.join(S_list)

str_list = deque()
str_list.append(S_n)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())
  
from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

if check % 2 == 1:
    S_list = list(reversed(S_list))

str_list = deque()
str_list.append(S)
count = 0
for i in range(Q):
    operate(i)
print(''.join(str_list))

Fixed submission:
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

S_list = [i for i in S]
if check % 2 == 1:
    S_list = list(reversed(S_list))

S_n = ''.join(S_list)

str_list = deque()
str_list.append(S_n)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

def operate(i):
    global count, S_n, word
    str_list = [S_n]
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                word = [Q_list[i][2]] + str_list
            else:
                word = str_list + [Q_list[i][2]]
        else:
            if Q_list[i][1] == '1':
                word = str_list + [Q_list[i][2]]
            else:
                word = [Q_list[i][2]] + str_list
    
    S_n = ''.join(word)

S_list = [i for i in S]
check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

if check % 2 == 1:
    S_list = list(reversed(S_list))

S_n = ''.join(S_list)

count = check % 2
for i in range(Q):
    operate(i)
print(''.join(S_n))

Fixed submission:
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

S_list = [i for i in S]
if check % 2 == 1:
    S_list = list(reversed(S_list))

S_n = ''.join(S_list)

str_list = deque()
str_list.append(S_n)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

def operate(i):
    global S_list, count
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                S_list = [Q_list[i][2]] + S_list
            else:
                S_list = S_list + [Q_list[i][2]]
        else:
            if Q_list[i][1] == '1':
                S_list = S_list + [Q_list[i][2]]
            else:
                S_list = [Q_list[i][2]] + S_list
 
S_list = [i for i in S]
check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1
if check % 2 == 1:
    S_list = list(reversed(S_list))

count = check % 2
for i in range(Q):
    operate(i)
print(''.join(S_list))

Fixed submission:
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

S_list = [i for i in S]
if check % 2 == 1:
    S_list = list(reversed(S_list))

S_n = ''.join(S_list)

str_list = deque()
str_list.append(S_n)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

S_list = [i for i in S]
def operate(i):
    global S_list
    if Q_list[i][0] == '1':
        S_list = list(reversed(S_list))
    else:
        Q_i = [k for k in Q_list[i][2]]
        if Q_list[i][1] == '1':
            S_list = Q_i + S_list
        else:
            S_list = S_list + Q_i
 
for i in range(Q):
    operate(i)
print(''.join(S_list))

Fixed submission:
S = input()
Q = int(input())
Q_list = list()
for i in range(Q):
    Q_list.append(input().split())

from collections import deque
def operate(i):
    global count, str_list
    if Q_list[i][0] == '1':
        count += 1
    else:
        if count % 2 == 0:
            if Q_list[i][1] == '1':
                str_list.appendleft(Q_list[i][2])
            else:
                str_list.append(Q_list[i][2])
        else:
            if Q_list[i][1] == '1':
                str_list.append(Q_list[i][2])
            else:
                str_list.appendleft(Q_list[i][2])

check = 0
for i in range(Q):
    if Q_list[i][0] == '1':
        check += 1

S_list = [i for i in S]
if check % 2 == 1:
    S_list = list(reversed(S_list))

S_n = ''.join(S_list)

str_list = deque()
str_list.append(S_n)
count = check%2
for i in range(Q):
    operate(i)
print(''.join(str_list))