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

S = input()
Q = int(input())
reverse_cnt = 1
index = []
s = deque([])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt *= -1
        index = list(np.array(index) * -1)
    else:
        s.append(query[2])
        if query[1] == "1":
            index.append(-1)
        else:
            index.append(1)

if reverse_cnt == -1:
    S = S[::-1]

insert = ""
add = ""

for i in index:
    if i == 1:
        add += s.popleft()
    elif i == -1:
        insert += s.popleft()

print(insert[::-1] + S + add)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")

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

S = input()
Q = int(input())
reverse_cnt = 0
index = []
s = deque([])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
        index = list(np.array(index) * -1)
    else:
        s.append(query[2])
        if query[1] == "1":
            index.append(-1)
        else:
            index.append(1)

if reverse_cnt % 2 != 0:
    S = S[::-1]

insert = ""
add = ""

for i in index:
    if i == 1:
        add += s.popleft()
    elif i == -1:
        insert += s.popleft()

print(insert[::-1] + S + add)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")

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

S = input()
Q = int(input())
reverse_cnt = 0
index = np.array([0 for _ in range(Q)])
s = deque([])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
        index = index * -1
    else:
        s.append(query[2])
        if query[1] == "1":
            index[i] = -1
        else:
            index[i] = 1

if reverse_cnt % 2 != 0:
    S = S[::-1]
    
for i in index:
    if i == 1:
        S += s.popleft()
    elif i == -1:
        S = s.popleft() + S

print(S)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
S = input()
Q = int(input())
reverse_cnt = 0
index = np.array([0 for _ in range(Q)])
s = []
for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
        index = index * -1
    else:
        s.append(query[2])
        if query[1] == "1":
            index[i] = -1
        else:
            index[i] = 1

index = [i for i in index if i != 0]

if reverse_cnt % 2 != 0:
    S = S[::-1]

for k, j in zip(index, s):
    if k == 1:
        S += j
    else:
        S = j + S

print(S)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse_cnt = 0
tmp = "*"
for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
        tmp = tmp[::-1]
    else:
        if query[1] == "1":
            tmp =  query[2] + tmp
        else:
            tmp = tmp + query[2] 

if reverse_cnt % 2 != 0:
    S = S[::-1]
    
print(tmp.replace("*", S))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")

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

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        S = S[::-1]
    else:
        f_i = int(query[1])
        c_i = query[2]
        if f_i == 1:
            S = c_i + S
        else:
            S = S + c_i
print(S)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
S = [s for s in S]

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        S = S[::-1]
    else:
        f_i = int(query[1])
        c_i = query[2]
        if f_i == 1:
            S.insert(0, c_i)
        else:
            S.append(c_i)
print("".join(S))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
reverse_cnt = 0
s = deque([i for i in S])

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        reverse_cnt += 1
    else:
        if query[1] == "1":
            if reverse_cnt % 2 == 0:
                s.appendleft(query[2])
            else:
                s.append(query[2])
        else:
            if reverse_cnt % 2 == 0:
                s.append(query[2])
            else:
                s.appendleft(query[2])

if reverse_cnt % 2 == 0:
    while s:
        print(s.popleft(), end="")
else:
     while s:
        print(s.pop(), end="")