Buggy python submission (verdict: Time Limit Exceeded):
def Main(S, Q, queries):
    ans = S
    flipped = False
    T1 = 0
    for q in queries:
        if int(q[0]) == 1:
            if not flipped:
                flipped = True
            else:
                flipped = False
            continue
        else:
            if int(q[1]) == 1:
                if flipped:
                    ans += q[2]
                else:
                    a = q[2] + ans
                    ans = a
            else:
                if flipped:
                    a = q[2] + ans
                    ans = a
                else:
                    ans += q[2]
    if flipped:
        l = list(ans)
        l.reverse()
        ans = "".join(l)
    return ans
        

def main():
    S = str(input())
    Q = int(input())
    queries = []
    for i in range(Q):
        queries.append(list(map(str, input().split())))
    print(Main(S, Q, queries))

if __name__ == '__main__':
    main()

Fixed submission:
def Main(S, Q, queries):
    right = S
    left = ""
    flipped = False
    T1 = 0
    for q in queries:
        if int(q[0]) == 1:
            if not flipped:
                flipped = True
            else:
                flipped = False
            continue
        else:
            if int(q[1]) == 1:
                if flipped:
                    right += q[2]
                else:
                    left += q[2]
            else:
                if not flipped:
                    right += q[2]
                else:
                    left += q[2]
    le = list(left)
    le.reverse()
    left = "".join(le)
    ans = left + right
    if flipped:
        l = list(ans)
        l.reverse()
        ans = "".join(l)
    return ans
        

def main():
    S = str(input())
    Q = int(input())
    queries = []
    for i in range(Q):
        queries.append(list(map(str, input().split())))
    print(Main(S, Q, queries))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def Main(S, Q, queries):
    ans = list(S)
    flipped = False
    T1 = 0
    for q in queries:
        if int(q[0]) == 1:
            if not flipped:
                flipped = True
            else:
                flipped = False
            continue
        else:
            if int(q[1]) == 1:
                if flipped:
                    ans.append(q[2])
                else:
                    ans.insert(0, q[2])
            else:
                if flipped:
                    ans.insert(0, q[2])
                else:
                    ans.append(q[2])
    if flipped:
        ans.reverse()
    return "".join(ans)
        

def main():
    S = str(input())
    Q = int(input())
    queries = []
    for i in range(Q):
        queries.append(list(map(str, input().split())))
    print(Main(S, Q, queries))

if __name__ == '__main__':
    main()

Fixed submission:
def Main(S, Q, queries):
    right = S
    left = ""
    flipped = False
    T1 = 0
    for q in queries:
        if int(q[0]) == 1:
            if not flipped:
                flipped = True
            else:
                flipped = False
            continue
        else:
            if int(q[1]) == 1:
                if flipped:
                    right += q[2]
                else:
                    left += q[2]
            else:
                if not flipped:
                    right += q[2]
                else:
                    left += q[2]
    le = list(left)
    le.reverse()
    left = "".join(le)
    ans = left + right
    if flipped:
        l = list(ans)
        l.reverse()
        ans = "".join(l)
    return ans
        

def main():
    S = str(input())
    Q = int(input())
    queries = []
    for i in range(Q):
        queries.append(list(map(str, input().split())))
    print(Main(S, Q, queries))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def Main(S, Q, queries):
    ans = list(S)
    flipped = False
    T1 = 0
    for q in queries:
        if int(q[0]) == 1:
            if not flipped:
                flipped = True
            else:
                flipped = False
            continue
        else:
            if int(q[1]) == 1:
                if flipped:
                    ans.append(q[2])
                else:
                    ans.insert(0, q[2])
            else:
                if flipped:
                    ans.insert(0, q[2])
                else:
                    ans.append(q[2])
    if flipped:
        ans.reverse()
    return "".join(ans)
        

def main():
    S = str(input())
    Q = int(input())
    queries = []
    for i in range(Q):
        queries.append(list(map(str, input().split())))
    print(Main(S, Q, queries))

if __name__ == '__main__':
    main()

Fixed submission:
def Main(S, Q, queries):
    right = S
    left = ""
    flipped = False
    T1 = 0
    for q in queries:
        if int(q[0]) == 1:
            if not flipped:
                flipped = True
            else:
                flipped = False
            continue
        else:
            if int(q[1]) == 1:
                if flipped:
                    right += q[2]
                else:
                    left += q[2]
            else:
                if not flipped:
                    right += q[2]
                else:
                    left += q[2]
    le = list(left)
    le.reverse()
    left = "".join(le)
    ans = left + right
    if flipped:
        l = list(ans)
        l.reverse()
        ans = "".join(l)
    return ans
        

def main():
    S = str(input())
    Q = int(input())
    queries = []
    for i in range(Q):
        queries.append(list(map(str, input().split())))
    print(Main(S, Q, queries))

if __name__ == '__main__':
    main()