Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
Q = int(input())
reverse = False
for i in range(Q):
    query = list(map(str,input().split()))
    if query[0] == '1':
        if reverse == True:
            reverse = False
        else:
            reverse = True
    if query[0] == '2':
        if query[1] == '1':
            if reverse == False:
                S = query[2] + S
            else:
                S = S + query[2]
        else:
            if reverse == True:
                S = query[2] + S
            else:
                S = S + query[2]
if reverse == True:
    S = S[::-1]
print(S)

Fixed submission:
S = str(input())
Q = int(input())
s1 = ''
s2 = ''
reverse = False
for i in range(Q):
    query = list(map(str,input().split()))
    if query[0] == '1':
        if reverse == True:
            reverse = False
        else:
            reverse = True
    if query[0] == '2':
        if query[1] == '1':
            if reverse == False:
                s1 = query[2] + s1
            else:
                s2 = s2 + query[2]
        else:
            if reverse == True:
                s1 = query[2] + s1
            else:
                s2 = s2 + query[2]
S = s1 + S + s2
if reverse == True:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(str(input()))
Q = int(input())
reverse = False
for i in range(Q):
    query = list(map(str,input().split()))
    if query[0] == '1':
        if reverse == True:
            reverse = False
        else:
            reverse = True
    if query[0] == '2':
        if query[1] == '1':
            if reverse == False:
                S.insert(0, query[2])
            else:
                S.append(query[2])
        else:
            if reverse == True:
                S.insert(0, query[2])
            else:
                S.append(query[2])
if reverse == True:
    S.reverse()
print(*S, sep = '')

Fixed submission:
S = str(input())
Q = int(input())
s1 = ''
s2 = ''
reverse = False
for i in range(Q):
    query = list(map(str,input().split()))
    if query[0] == '1':
        if reverse == True:
            reverse = False
        else:
            reverse = True
    if query[0] == '2':
        if query[1] == '1':
            if reverse == False:
                s1 = query[2] + s1
            else:
                s2 = s2 + query[2]
        else:
            if reverse == True:
                s1 = query[2] + s1
            else:
                s2 = s2 + query[2]
S = s1 + S + s2
if reverse == True:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(str(input()))
Q = int(input())
for i in range(Q):
    query = list(map(str,input().split()))
    if query[0] == '1':
        S.reverse()
    if query[0] == '2':
        if query[1] == '1':
            S.insert(0, query[2])
        else:
            S.append(query[2])
print(*S, sep = '')

Fixed submission:
S = str(input())
Q = int(input())
s1 = ''
s2 = ''
reverse = False
for i in range(Q):
    query = list(map(str,input().split()))
    if query[0] == '1':
        if reverse == True:
            reverse = False
        else:
            reverse = True
    if query[0] == '2':
        if query[1] == '1':
            if reverse == False:
                s1 = query[2] + s1
            else:
                s2 = s2 + query[2]
        else:
            if reverse == True:
                s1 = query[2] + s1
            else:
                s2 = s2 + query[2]
S = s1 + S + s2
if reverse == True:
    S = S[::-1]
print(S)