Buggy python submission (verdict: Runtime Error):
    S = input()
    Q = int(input())
     
    # print(S, Q)
     
    queries = []
    for i in range(Q):
        query = input()
        queries.append(query)
     
    from collections import deque
    slist = deque()
	slist.append(S)
    for query in queries:
        if query == "1":
            isReversed = not isReversed
        else:
            t, f, c = query.split()
            if f == '1':
                if isReversed:
                    slist.append(c)
                else:
                    slist.appendleft(c)
            else:
                if isReversed:
                    slist.appendleft(c)
                else:
                    slist.append(c)
     
    if isReversed:
        slist.reverse()
    print("".join(slist))

Fixed submission:
S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))

Buggy python submission (verdict: Runtime Error):

S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque()
slist.append(S)
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f=="1"
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)
if isReversed:
    slist.reverse()

print("".join(slist))


Fixed submission:
S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))

Buggy python submission (verdict: Time Limit Exceeded):

S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)


isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
        # print("reverse", S)
        # S = S[::-1]
    else:
        t, f, c = query.split()
        # print(t, f, c)
        d = f=="1"
        if isReversed: d = not d
        if d:
            S = "".join([c, S])
        else:
            # print("append c to tail of ", S)
            # S = S + c
            S = "".join([S, c])

if isReversed:
    S = S[::-1]
print(S)

Fixed submission:
S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))

Buggy python submission (verdict: Time Limit Exceeded):

S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)


isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
        # print("reverse", S)
        # S = S[::-1]
    else:
        t, f, c = query.split()
        # print(t, f, c)
        d = f=="1"
        if isReversed: d = not d
        if d:
            S = c + S
        else:
            # print("append c to tail of ", S)
            S = S + c

if isReversed:
    S = S[::-1]
print(S)

Fixed submission:
S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))

Buggy python submission (verdict: Time Limit Exceeded):

S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)



for query in queries:
    if query == "1":
        # print("reverse", S)
        S = S[::-1]
    else:
        t, f, c = query.split()
        # print(t, f, c)
        if f =="1":
            # print("append c to head of", S)
            S = c + S
        else:
            # print("append c to tail of ", S)
            S = S + c

print(S)

Fixed submission:
S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))

Buggy python submission (verdict: Time Limit Exceeded):

S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)



for query in queries:
    if query == "1":
        # print("reverse", S)
        S = S[::-1]
    else:
        t, f, c = query.split()
        # print(t, f, c)
        if f =="1":
            # print("append c to head of", S)
            S = c + S
        else:
            # print("append c to tail of ", S)
            S = S + c

print(S)

Fixed submission:
S = input()
Q = int(input())

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
even = True
for query in queries:
    if query == "1":
        even = not even
    else:
        t, f, c = query.split()
        if f == '1':
            if even:
                slist.appendleft(c)
            else:
                slist.append(c)
        else:
            if even:
                slist.append(c)
            else:
                slist.appendleft(c)
if not even:
    slist.reverse()

print(''.join(slist))