Buggy python submission (verdict: Runtime Error):
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    for i in ans[::-1]:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')

Fixed submission:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    ans.reverse()
    for i in ans:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')

Buggy python submission (verdict: Time Limit Exceeded):
def inv(s):
    t = ''
    for i in range(len(s)):
        t += s[-1 * (i + 1)]
    return t

s = input()
q = int(input())
ans = s
parity = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        parity += 1
    else:
        if qi[2] == '1' and parity % 2 == 0:
            ans = qi[4] + ans
        elif qi[2] == '2' and parity % 2 == 0:
            ans = ans + qi[4]
        if qi[2] == '1' and parity % 2 == 1:
            ans = ans + qi[4]
        elif qi[2] == '2' and parity % 2 == 1:
            ans = qi[4] + ans
if parity % 2:
    print(ans[::-1])
else:
    print(ans)

Fixed submission:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    ans.reverse()
    for i in ans:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')

Buggy python submission (verdict: Time Limit Exceeded):
def inv(s):
    t = ''
    for i in range(len(s)):
        t += s[-1 * (i + 1)]
    return t

s = input()
q = int(input())
ans = s
parity = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        parity += 1
    else:
        if qi[2] == '1' and parity % 2 == 0:
            ans = qi[4] + ans
        elif qi[2] == '2' and parity % 2 == 0:
            ans = ans + qi[4]
        if qi[2] == '1' and parity % 2 == 1:
            ans = ans + qi[4]
        elif qi[2] == '2' and parity % 2 == 1:
            ans = qi[4] + ans
if parity % 2:
    ans = inv(ans)
print(ans)

Fixed submission:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    ans.reverse()
    for i in ans:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')

Buggy python submission (verdict: Time Limit Exceeded):
def inv(s):
    t = ''
    for i in range(len(s)):
        t += s[-1 * (i + 1)]
    return t

s = input()
q = int(input())
ans = s
for i in range(q):
    qi = input()
    if qi[0] == '1':
        ans = inv(ans)
    else:
        if qi[2] == '1':
            ans = qi[4] + ans
        elif qi[2] == '2':
            ans = ans + qi[4]
print(ans)

Fixed submission:
from collections import deque
s = input()
q = int(input())
ans = deque(s)
rev = 0
for i in range(q):
    qi = input()
    if qi[0] == '1':
        rev += 1
    else:
        if qi[2] == '1' and rev % 2 == 0:
            ans.appendleft(qi[4])
        elif qi[2] == '2' and rev % 2 == 0:
            ans.append(qi[4])
        if qi[2] == '1' and rev % 2 == 1:
            ans.append(qi[4])
        elif qi[2] == '2' and rev % 2 == 1:
            ans.appendleft(qi[4])

parity = rev % 2
if parity:
    ans.reverse()
    for i in ans:
        print(i, end='')
else:
    for i in ans:
        print(i, end='')