Buggy python submission (verdict: Runtime Error):
from queue import deque

s = deque([i for i in input()])
Q = int(input())
state = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if q[2] == '1':
            if state == 0:
                s.appendleft(q[-1])
            else:
                s.append(q[-1])
        else:
            if state == 0:
                s.append(q[-1])
            else:
                s.appendleft(q[-1])

if state == 1:
    print(s[::-1])
else:
    print(s)


Fixed submission:
from queue import deque

s = deque([i for i in input()])
Q = int(input())
state = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if int(q[2]) == 1:
            if state == 0:
                s.appendleft(q[-1])
            else:
                s.append(q[-1])
        elif int(q[2]) == 2:
            if state == 0:
                s.append(q[-1])
            else:
                s.appendleft(q[-1])

if state == 1:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())
state = 0
for q in range(Q):
    query = input()
    if query[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if query[2] == '1':
            if state == 0:
                s = query[-1] + s
            else:
                s += query[-1]
        else:
            if state == 0:
                s += query[-1]
            else:
                s = query[-1] + s

if state == 1:
    print(s[::-1])
else:
    print(s)


Fixed submission:
from queue import deque

s = deque([i for i in input()])
Q = int(input())
state = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if int(q[2]) == 1:
            if state == 0:
                s.appendleft(q[-1])
            else:
                s.append(q[-1])
        elif int(q[2]) == 2:
            if state == 0:
                s.append(q[-1])
            else:
                s.appendleft(q[-1])

if state == 1:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())
state = 0
for q in range(Q):
    query = input()
    if query[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if query[2] == '1':
            if state == 0:
                s = query[-1] + s
            else:
                s += query[-1]
        else:
            if state == 0:
                s += query[-1]
            else:
                s = query[-1] + s

if state == 1:
    print(s[::-1])
else:
    print(s)


Fixed submission:
from queue import deque

s = deque([i for i in input()])
Q = int(input())
state = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if int(q[2]) == 1:
            if state == 0:
                s.appendleft(q[-1])
            else:
                s.append(q[-1])
        elif int(q[2]) == 2:
            if state == 0:
                s.append(q[-1])
            else:
                s.appendleft(q[-1])

if state == 1:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())
for q in range(Q):
    query = input()
    if query[0] == '1':
        s = s[::-1]
    else:
        if query[2] == '1':
            s = query[-1] + s
        else:
            s += query[-1]

print(s)


Fixed submission:
from queue import deque

s = deque([i for i in input()])
Q = int(input())
state = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if int(q[2]) == 1:
            if state == 0:
                s.appendleft(q[-1])
            else:
                s.append(q[-1])
        elif int(q[2]) == 2:
            if state == 0:
                s.append(q[-1])
            else:
                s.appendleft(q[-1])

if state == 1:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
Q = int(input())
for q in range(Q):
    query = input()
    if query[0] == '1':
        s = s[::-1]
    else:
        if query[2] == '1':
            s = query[-1] + s
        else:
            s += query[-1]

print(s)


Fixed submission:
from queue import deque

s = deque([i for i in input()])
Q = int(input())
state = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if int(q[2]) == 1:
            if state == 0:
                s.appendleft(q[-1])
            else:
                s.append(q[-1])
        elif int(q[2]) == 2:
            if state == 0:
                s.append(q[-1])
            else:
                s.appendleft(q[-1])

if state == 1:
    s.reverse()
print(''.join(s))