Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

f = 1
tail1 = []
head1 = []
for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == "1":
        f *= -1
    else:
        j,x,s1 = i
        if x == "1":
            if f == 1:
                head1 = [s1] + head1
            else:
                tail1 = tail1 + [s1]
        else:
            if f == -1:
                head1 = [s1] + head1
            else:
                tail1 = tail1 + [s1]

s2 = (head1 + s + tail1)
if f == -1:
    s2.reverse()

print("".join(s2))

Fixed submission:
from collections import deque
 
S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

f = 1
tail1 = []
head1 = []
for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == "1":
        f *= -1
    else:
        j,x,s1 = i
        if x == "1":
            if f == 1:
                head1 = [s1] + head1
            else:
                tail1 = tail1 + [s1]
        else:
            if f == -1:
                head1 = [s1] + head1
            else:
                tail1 = tail1 + [s1]

s2 = (head1 + s + tail1)
if f == -1:
    s2.reverse()

print("".join(s2))

Fixed submission:
from collections import deque
 
S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

f = 1
tail1 = []
head1 = []
for _ in range(q):
    i = list(map(str, input().split()))
    if i[0] == "1":
        f *= -1
    else:
        j,x,s1 = i
        if x == "1":
            if f == 1:
                head1 = [s1] + head1
            else:
                tail1 = tail1 + [s1]
        else:
            if f == -1:
                head1 = [s1] + head1
            else:
                tail1 = tail1 + [s1]

s2 = (head1 + s + tail1)[::f]

print("".join(s2))

Fixed submission:
from collections import deque
 
S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))

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

f = 1
tail1 = []
head1 = []
for i in q1:
    if i[0] == "1":
        f *= -1
    else:
        j,x,s1 = i
        if (x == "1" and f == 1) or (x == "2" and f == -1):
            head1 = [s1] + head1
        else:
            tail1 = tail1 + [s1]

s2 = (head1 + s + tail1)[::f]

print("".join(s2))

Fixed submission:
from collections import deque
 
S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
o = 1
for i in range(q):
    x = input().split()
    if x[0] == "1":
        o = o*-1
    else:
        if (x[1] == "1" and o == 1) or (x[1] == "2" and o == -1):
            s = x[2] + s
        else:
            s = s + x[2]

s = s[::o]
print(s)

Fixed submission:
from collections import deque
 
S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))

Buggy python submission (verdict: Time Limit Exceeded):
##
s = input()
q = int(input())
for i in range(q):
    x = input().split()
    if x[0] == "1":
        s = s[::-1]
    else:
        if x[1] == "1":
            s = x[2] + s
        else:
            s = s + x[2]

print(s)

Fixed submission:
from collections import deque
 
S = input()
L = deque([])
for c in S:
    L.append(c)
Q = int(input())
flag = 1
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag *= -1
    else:
        F = q[1]
        if F == "1":
            if flag == 1:
                L.appendleft(q[2])
            else:
                L.append(q[2])
        else:
            if flag == 1:
                L.append(q[2])
            else:
                L.appendleft(q[2])
if flag == 1:
    print("".join(map(str, L)))
else:
    L.reverse()
    print("".join(map(str, L)))