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

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s = [L[2]] + s
            if L[1] == '2' :
                s = s + [L[2]]
        if head == 1:
            if L[1] == '1' :
                s = s + [L[2]]
            if L[1] == '2' :
                s = [L[2]] + s
if head == 0:
    print(''.join(s))
else: 
    print(''.join(reversed(s)))


Fixed submission:

from collections import deque

s = deque(list(input()))
q = int(input())
head = 0

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s.appendleft(L[2])
            if L[1] == '2' :
                s.append(L[2])
        if head == 1:
            if L[1] == '1' :
                s.append(L[2])
            if L[1] == '2' :
                s.appendleft(L[2])
if head == 0:
    print(''.join(s))
else: 
    print(''.join(reversed(s)))

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

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s = L[2] + s
            if L[1] == '2' :
                s = s + L[2]
        if head == 1:
            if L[1] == '1' :
                s = s + L[2]
            if L[1] == '2' :
                s = L[2] + s
if head == 0:
    print(s)
else: 
    s = ''.join(reversed(s))
    print(s)
        

Fixed submission:

from collections import deque

s = deque(list(input()))
q = int(input())
head = 0

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s.appendleft(L[2])
            if L[1] == '2' :
                s.append(L[2])
        if head == 1:
            if L[1] == '1' :
                s.append(L[2])
            if L[1] == '2' :
                s.appendleft(L[2])
if head == 0:
    print(''.join(s))
else: 
    print(''.join(reversed(s)))

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

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        s = ''.join(reversed(s))
    if L[0] == '2' :
        if L[1] == '1' :
            s = L[2] + s
        if L[1] == '2' :
            s = s + L[2]
print(s)
        

Fixed submission:

from collections import deque

s = deque(list(input()))
q = int(input())
head = 0

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s.appendleft(L[2])
            if L[1] == '2' :
                s.append(L[2])
        if head == 1:
            if L[1] == '1' :
                s.append(L[2])
            if L[1] == '2' :
                s.appendleft(L[2])
if head == 0:
    print(''.join(s))
else: 
    print(''.join(reversed(s)))

Buggy python submission (verdict: Time Limit Exceeded):

s = input()
q = int(input())
L = []
for i in range(q):
    L.append(list(input().split()))
    if L[-1][0] == '1' :
        s = ''.join(reversed(s))
    if L[-1][0] == '2' :
        if L[-1][1] == '1' :
            s = L[-1][2] + s
        if L[-1][1] == '2' :
            s = s + L[-1][2]
print(s)
        

Fixed submission:

from collections import deque

s = deque(list(input()))
q = int(input())
head = 0

for i in range(q):
    L = list(input().split())
    if L[0] == '1' :
        head = (head + 1)%2
    if L[0] == '2' :
        if head == 0:
            if L[1] == '1' :
                s.appendleft(L[2])
            if L[1] == '2' :
                s.append(L[2])
        if head == 1:
            if L[1] == '1' :
                s.append(L[2])
            if L[1] == '2' :
                s.appendleft(L[2])
if head == 0:
    print(''.join(s))
else: 
    print(''.join(reversed(s)))