Buggy python submission (verdict: Time Limit Exceeded):
S = input() 
Q = int(input())
def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

def pros(S, f, r, add):
    if f == 0:
        if r == "1":
            S = add + S
        elif r == "2":
            S = S + add
    elif f == 1:
        if r == "2":
            S = add + S
        elif r == "1":
            S = S + add
    return S

flag = 0
cnt = 0
for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
        cnt += 1
    elif lists[0] == "2":
        S = pros(S, flag, lists[1], lists[2])

if cnt % 2 == 1:
    S = S[::-1]

print(S)

Fixed submission:
S = input() 
Q = int(input())
rlist, llist = [], []
flag, cnt = 0, 0

def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

def pros(f, r, add):
    if f == 0:
        if r == "1":
            llist.append(lists[2])
        elif r == "2":
            rlist.append(lists[2])
    elif f == 1:
        if r == "2":
            llist.append(lists[2])
        elif r == "1":
            rlist.append(lists[2])

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
        cnt += 1
    else:
        pros(flag, lists[1], lists[2])
        
llist.reverse()
        
S = "".join(llist) + S + "".join(rlist)

if cnt % 2 == 1:
    S = S[::-1]
print(S)

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

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        S = S[::-1]
    elif lists[0] == "2":
        if lists[1] == "1":
            S = lists[2] + S
        elif lists[1] == "2":
            S = S + lists[2]

print(S)

Fixed submission:
S = input() 
Q = int(input())
rlist, llist = [], []
flag, cnt = 0, 0

def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

def pros(f, r, add):
    if f == 0:
        if r == "1":
            llist.append(lists[2])
        elif r == "2":
            rlist.append(lists[2])
    elif f == 1:
        if r == "2":
            llist.append(lists[2])
        elif r == "1":
            rlist.append(lists[2])

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
        cnt += 1
    else:
        pros(flag, lists[1], lists[2])
        
llist.reverse()
        
S = "".join(llist) + S + "".join(rlist)

if cnt % 2 == 1:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input() 
Q = int(input())
process_list = [input().split() for i in range(Q)]  #[ [2, 1, p], [1], [2, 2, c], [1] ]

for lists in process_list:
    if lists[0] == "1":
        S = S[::-1]
    elif lists[0] == "2":
        if lists[1] == "1":
            S = lists[2] + S
        elif lists[1] == "2":
            S = S + lists[2]

print(S)

Fixed submission:
S = input() 
Q = int(input())
rlist, llist = [], []
flag, cnt = 0, 0

def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

def pros(f, r, add):
    if f == 0:
        if r == "1":
            llist.append(lists[2])
        elif r == "2":
            rlist.append(lists[2])
    elif f == 1:
        if r == "2":
            llist.append(lists[2])
        elif r == "1":
            rlist.append(lists[2])

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
        cnt += 1
    else:
        pros(flag, lists[1], lists[2])
        
llist.reverse()
        
S = "".join(llist) + S + "".join(rlist)

if cnt % 2 == 1:
    S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input() 
Q = int(input())
process_list = [input().split() for i in range(Q)]  #[ [2, 1, p], [1], [2, 2, c], [1] ]

for lists in process_list:
    if lists[0] == "1":
        lists[0] = int(lists[0])
    if lists[0] == "2":
        lists[0] = int(lists[0])
        lists[1] = int(lists[1])

for lists in process_list:
    if lists[0] == 1:
        S = S[::-1]
    elif lists[0] == 2:
        if lists[1] == 1:
            S = lists[2] + S
        elif lists[1] == 2:
            S = S + lists[2]

print(S)

Fixed submission:
S = input() 
Q = int(input())
rlist, llist = [], []
flag, cnt = 0, 0

def trans(f):
    if f == 1:
        f = 0
    elif f == 0:
        f = 1
    return f

def pros(f, r, add):
    if f == 0:
        if r == "1":
            llist.append(lists[2])
        elif r == "2":
            rlist.append(lists[2])
    elif f == 1:
        if r == "2":
            llist.append(lists[2])
        elif r == "1":
            rlist.append(lists[2])

for i in range(Q):
    lists = input().split()
    if lists[0] == "1":
        flag = trans(flag)
        cnt += 1
    else:
        pros(flag, lists[1], lists[2])
        
llist.reverse()
        
S = "".join(llist) + S + "".join(rlist)

if cnt % 2 == 1:
    S = S[::-1]
print(S)