Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
inversion_flg = False
# L = [input().split() for _ in range(Q)]

for i in range(Q):
    L = input().split()
    if L[0] == '1':
        if inversion_flg:
            inversion_flg = False
        else:
            inversion_flg = True
    # if L[0] == '2':
    else:
        if not inversion_flg:
            if L[1] == '1':
                S = L[2] + S
            else:
                S = S + L[2]
        else:
            if L[1] == '2':
                S = L[2] + S
            else:
                S = S + L[2]



# print(L)
if not inversion_flg: 
    print(S)
else:
    # S.reverse()
    S = S[::-1]
    print(S)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
inversion_flg = False
# L = [input().split() for _ in range(Q)]

for i in range(Q):
    L = input().split()
    if L[0] == '1':
        if inversion_flg:
            inversion_flg = False
        else:
            inversion_flg = True
    if L[0] == '2':
        if not inversion_flg:
            if L[1] == '1':
                S = L[2] + S
            else:
                S = S + L[2]
        else:
            if L[1] == '2':
                S = L[2] + S
            else:
                S = S + L[2]



# print(L)
if not inversion_flg: 
    print(S)
else:
    # S.reverse()
    S = S[::-1]
    print(S)

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
inversion_flg = False
# L = [input().split() for _ in range(Q)]

for i in range(Q):
    L = input().split()
    if L[0] == '1':
        if inversion_flg:
            inversion_flg = False
        else:
            inversion_flg = True
    if L[0] == '2':
        if not inversion_flg:
            if L[1] == '1':
                S = [L[2]] + S
            else:
                S = S + [L[2]]
        else:
            if L[1] == '2':
                S = [L[2]] + S
            else:
                S = S + [L[2]]



# print(L)
if not inversion_flg: 
    print(''.join(S))
else:
    # S.reverse()
    S = S[::-1]
    print(''.join(S))

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
inversion_flg = False
# L = [input().split() for _ in range(Q)]

for i in range(Q):
    L = input().split()
    if L[0] == '1':
        if inversion_flg:
            inversion_flg = False
        else:
            inversion_flg = True
    if L[0] == '2':
        if not inversion_flg:
            if L[1] == '1':
                S = [L[2]] + S
            else:
                S = S + [L[2]]
        else:
            if L[1] == '2':
                S = [L[2]] + S
            else:
                S = S + [L[2]]



# print(L)
if not inversion_flg: 
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
import time
# L = [input().split() for _ in range(Q)]

count = 0 # ['1']の数
for i in range(Q):
    L = input().split()
    if L[0] == '1':
        count += 1
    if L[0] == '2':
        if (count % 2) == 0:
            count = 0
            if L[1] == '1':
                S = [L[2]] + S
            else:
                S = S + [L[2]]
        else:
            if L[1] == '2':
                S = [L[2]] + S
            else:
                S = S + [L[2]]



# print(L)
if (count % 2) == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
# L = [input().split() for _ in range(Q)]

count = 0 # ['1']の数
for i in range(Q):
    L = input().split()
    if L[0] == '1':
        count += 1
    if L[0] == '2':
        if (count % 2) == 0:
            if L[1] == '1':
                S = [L[2]] + S
            else:
                S = S + [L[2]]
        else:
            if L[1] == '2':
                S = [L[2]] + S
            else:
                S = S + [L[2]]



# print(L)
if (count % 2) == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
L = [input().split() for _ in range(Q)]

count = 0 # ['1']の数
for i in range(len(L)):
    if L[i][0] == '1':
        count += 1
    if L[i][0] == '2':
        if (count % 2) == 0:
            if L[i][1] == '1':
                S = [L[i][2]] + S
            else:
                S = S + [L[i][2]]
        else:
            if L[i][1] == '2':
                S = [L[i][2]] + S
            else:
                S = S + [L[i][2]]



# print(L)
if (count % 2) == 0:
    print(''.join(S))
else:
    S.reverse()
    print(''.join(S))

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
L = [input().split() for _ in range(Q)]

def syori(item):
    global S
    if item[0] == '1':
        S.reverse()
    else:
        # Ti = 2 の時
        if item[1] == '1':
            S = [item[2]] + S
        else:
            S = S + [item[2]]

for item in L:
    syori(item)
# print(L)
print(''.join(S))

Fixed submission:
s = input()
q = int(input())
query = []
lead = ''
end = ''
inversion_flg = False
 
for j in range(q):
    i = input().split()
    if i[0] == "1":
        if inversion_flg:
            inversion_flg = False 
        else:
            inversion_flg = True
    else:
        if inversion_flg:
            if i[1] == "1":
                i[1] = "2"
            else:
                i[1] = "1"
        if i[1] == "1":
            lead+=i[2]
        else:
            end+=i[2]
 
lead = lead[::-1]
s = lead+s+end
if inversion_flg:
    s = s[::-1]
print(s)