Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    reverse = False
    front = ""
    back = ""
    for _ in range(Q):
        TFC = list(input().split())
        if len(TFC) == 1:
            reverse = not(reverse)
        else:
            t,f,c = TFC
            if reverse:
                if f == "2":
                    front += c
                else:
                    back += c

            else:
                if f == "1":
                    front += c
                else:
                    back += c
    if reverse:
        print(back[::-1] + S[::-1] + front)
    else:
        print(front[::-1] + S + back)
    return

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    S = input()
    Q = int(input())
    reverse = False
    front = []
    back = []
    for _ in range(Q):
        TFC = list(input().split())
        if len(TFC) == 1:
            reverse = not(reverse)
        else:
            t,f,c = TFC
            if reverse:
                if f == "2":
                    front.append(c)
                else:
                    back.append(c)

            else:
                if f == "1":
                    front.append(c)
                else:
                    back.append(c)
    if reverse:
        print("".join(back[::-1]) + S[::-1] + "".join(front))
    else:
        print("".join(front[::-1]) + S + "".join(back))
    return

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    reverse = False

    for _ in range(Q):
        TFC = list(input().split())
        if len(TFC) == 1:
            reverse = not(reverse)
        else:
            t,f,c = TFC
            if reverse:
                if f == "2":
                    S = c + S
                else:
                    S = S + c

            else:
                if f == "1":
                    S = c + S
                else:
                    S = S + c
    if reverse:
        print(S[::-1])
    else:
        print(S)
    return

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    S = input()
    Q = int(input())
    reverse = False
    front = []
    back = []
    for _ in range(Q):
        TFC = list(input().split())
        if len(TFC) == 1:
            reverse = not(reverse)
        else:
            t,f,c = TFC
            if reverse:
                if f == "2":
                    front.append(c)
                else:
                    back.append(c)

            else:
                if f == "1":
                    front.append(c)
                else:
                    back.append(c)
    if reverse:
        print("".join(back[::-1]) + S[::-1] + "".join(front))
    else:
        print("".join(front[::-1]) + S + "".join(back))
    return

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    S = input()
    Q = int(input())
    reverse = False

    for _ in range(Q):
        TFC = list(input().split())
        if len(TFC) == 1:
            reverse = not(reverse)
        else:
            t,f,c = TFC
            if reverse:
                if f == "2":
                    S = c + S
                else:
                    S = S + c

            else:
                if f == "1":
                    S = c + S
                else:
                    S = S + c
    if reverse:
        print(S[::-1])
    else:
        print(S)
    return

if __name__ == "__main__":
    main()

Fixed submission:
def main():
    S = input()
    Q = int(input())
    reverse = False
    front = []
    back = []
    for _ in range(Q):
        TFC = list(input().split())
        if len(TFC) == 1:
            reverse = not(reverse)
        else:
            t,f,c = TFC
            if reverse:
                if f == "2":
                    front.append(c)
                else:
                    back.append(c)

            else:
                if f == "1":
                    front.append(c)
                else:
                    back.append(c)
    if reverse:
        print("".join(back[::-1]) + S[::-1] + "".join(front))
    else:
        print("".join(front[::-1]) + S + "".join(back))
    return

if __name__ == "__main__":
    main()