Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
num_query = int(input())

rev = False
for i in range(num_query):
    query = input().split()
    if len(query) == 1:
        if rev == True:
            rev = False
        else:
            rev = True
    else:
        if rev == False:
            if query[1] == "1":
                S = list(query[2]) + S
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S = list(query[2]) + S
            else:
                S.append(query[2])

if rev == True:
    S = S[::-1]
    
print("".join(S))


Fixed submission:
S = input()
num_query = int(input())

rev_flag = False
head = []
tail = []
for i in range(num_query):
    query = input().split()
    if len(query) == 1:
        if rev_flag == True:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag == False:
            if query[1] == "1":
                head.append(query[2])
            else:
                tail.append(query[2])
        else:
            if query[1] == "1":
                tail.append(query[2])
            else:
                head.append(query[2])

head = "".join(head)
head = head[::-1]
tail = "".join(tail)
ans = head + S + tail

if rev_flag == True:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
num_query = int(input())

for i in range(num_query):
    query = input().split()
    if len(query) == 1:
        S = S[::-1]
    else:
        if query[1] == "1":
            S = list(query[2]) + S
        else:
            S.append(query[2])

print("".join(S))


Fixed submission:
S = input()
num_query = int(input())

rev_flag = False
head = []
tail = []
for i in range(num_query):
    query = input().split()
    if len(query) == 1:
        if rev_flag == True:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag == False:
            if query[1] == "1":
                head.append(query[2])
            else:
                tail.append(query[2])
        else:
            if query[1] == "1":
                tail.append(query[2])
            else:
                head.append(query[2])

head = "".join(head)
head = head[::-1]
tail = "".join(tail)
ans = head + S + tail

if rev_flag == True:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
num_query = int(input())

for i in range(num_query):
    query = input().split()
    if len(query) == 1:
        S = S[::-1]
    else:
        if query[1] == "1":
            S.insert(0, query[2])
        else:
            S.append(query[2])

print("".join(S))


Fixed submission:
S = input()
num_query = int(input())

rev_flag = False
head = []
tail = []
for i in range(num_query):
    query = input().split()
    if len(query) == 1:
        if rev_flag == True:
            rev_flag = False
        else:
            rev_flag = True
    else:
        if rev_flag == False:
            if query[1] == "1":
                head.append(query[2])
            else:
                tail.append(query[2])
        else:
            if query[1] == "1":
                tail.append(query[2])
            else:
                head.append(query[2])

head = "".join(head)
head = head[::-1]
tail = "".join(tail)
ans = head + S + tail

if rev_flag == True:
    ans = ans[::-1]

print(ans)