Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque


def LS():
    return list(input().split())


S = deque(input())
Q = int(input())
rev = 0
for i in range(Q):
    A = LS()
    if A[0] == "1":
        rev += 1
        rev %= 2
    else:
        if A[1] == "1":
            if rev == 0:
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if rev == 0:
                S.append(A[2])
            else:
                S.appendleft(A[2])
if rev == 0:
    for i in range(len(S)):
        print(S[i], end="")
else:
    for i in range(len(S)-1, -1, -1):
        print(S[i], end="")


Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
reverse = 0
Tlist = []
for i in range(Q):
    Tlist.append(list(input().split()))
    if Tlist[i][0] == str(2):
        if (int(Tlist[i][1])+reverse) % 2 == 0:
            S.append(Tlist[i][2])
        else:
            S.appendleft(Tlist[i][2])
    else:
        if reverse == 1:
            reverse = 0
        else:
            reverse = 1
if reverse == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def LS():
    return list(input().split())


S = input()
Q = int(input())
rev = 0
for i in range(Q):
    A = LS()
    if A[0] == "1":
        rev += 1
        rev %= 2
    else:
        if A[1] == "1":
            if rev == 0:
                S = A[2]+S
            else:
                S = S+A[2]
        else:
            if rev == 0:
                S = S+A[2]
            else:
                S = A[2]+S
if rev == 0:
    print(S)
    sys.exit()
else:
    S = list(S)
    S.reverse()
for i in range(len(S)):
    print(S[i], end="")


Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
reverse = 0
Tlist = []
for i in range(Q):
    Tlist.append(list(input().split()))
    if Tlist[i][0] == str(2):
        if (int(Tlist[i][1])+reverse) % 2 == 0:
            S.append(Tlist[i][2])
        else:
            S.appendleft(Tlist[i][2])
    else:
        if reverse == 1:
            reverse = 0
        else:
            reverse = 1
if reverse == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
def LS():
    return list(input().split())


S = input()
Q = int(input())
rev = 0
for i in range(Q):
    A = LS()
    if A[0] == "1":
        rev += 1
        rev %= 2
    else:
        if A[1] == "1":
            if rev == 0:
                S = A[2]+S
            else:
                S = S+A[2]
        else:
            if rev == 0:
                S = S+A[2]
            else:
                S = A[2]+S
if rev == 0:
    ans = S
else:
    ans = S[::-1]
print(ans)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
reverse = 0
Tlist = []
for i in range(Q):
    Tlist.append(list(input().split()))
    if Tlist[i][0] == str(2):
        if (int(Tlist[i][1])+reverse) % 2 == 0:
            S.append(Tlist[i][2])
        else:
            S.appendleft(Tlist[i][2])
    else:
        if reverse == 1:
            reverse = 0
        else:
            reverse = 1
if reverse == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))