Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def main():
    input = stdin.readline
    S = [input()[:-1]]
    Q = int(input())
    L = []
    R = []
    is_turned = False

    for _ in range(Q):
        query = input()[:-1]
        if query == "1":
            is_turned = not is_turned
        else:
            T, F, C = query.split()
            if is_turned ^ (F == "1"):
                L.insert(0, C)
            else:
                R.append(C)

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    S = input()
    Q = int(input())
    L = ""
    R = ""
    is_turned = False

    for _ in range(Q):
        Query = input().split()
        if Query[0] == "1":
            is_turned = not is_turned
        else:
            if is_turned ^ (Query[1] == "1"):
                # L.insert(0, Query[2])
                L = Query[2] + L
            else:
                # R.append(Query[2])
                R = R + Query[2]

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin


def main():
    input = stdin.readline
    S = [input()[:-1]]
    Q = int(input())
    is_turned = False

    for _ in range(Q):
        query = input()[:-1]
        if query == "1":
            is_turned = not is_turned
        else:
            T, F, C = query.split()
            if is_turned ^ (F == "1"):
                S.insert(0, C)
            else:
                S.append(C)

    if (is_turned):
        print("".join(S)[::-1])
    else:
        print("".join(S))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    S = input()
    Q = int(input())
    L = ""
    R = ""
    is_turned = False

    for _ in range(Q):
        Query = input().split()
        if Query[0] == "1":
            is_turned = not is_turned
        else:
            if is_turned ^ (Query[1] == "1"):
                # L.insert(0, Query[2])
                L = Query[2] + L
            else:
                # R.append(Query[2])
                R = R + Query[2]

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()

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

    for _ in range(Q):
        query = input()
        if query == "1":
            is_turned = not is_turned
        else:
            T, F, C = query.split()
            if is_turned ^ (F == "1"):
                S.insert(0, C)
            else:
                S.append(C)

    if (is_turned):
        print("".join(S)[::-1])
    else:
        print("".join(S))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    S = input()
    Q = int(input())
    L = ""
    R = ""
    is_turned = False

    for _ in range(Q):
        Query = input().split()
        if Query[0] == "1":
            is_turned = not is_turned
        else:
            if is_turned ^ (Query[1] == "1"):
                # L.insert(0, Query[2])
                L = Query[2] + L
            else:
                # R.append(Query[2])
                R = R + Query[2]

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()

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

    for _ in range(Q):
        query = input()
        if query == "1":
            is_turned = not is_turned
        else:
            T, F, C = query.split()
            if is_turned ^ (F == "1"):
                S = [C] + S
            else:
                S = S + [C]

    if (is_turned):
        print("".join(S)[::-1])
    else:
        print("".join(S))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    S = input()
    Q = int(input())
    L = ""
    R = ""
    is_turned = False

    for _ in range(Q):
        Query = input().split()
        if Query[0] == "1":
            is_turned = not is_turned
        else:
            if is_turned ^ (Query[1] == "1"):
                # L.insert(0, Query[2])
                L = Query[2] + L
            else:
                # R.append(Query[2])
                R = R + Query[2]

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()

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

    for _ in range(Q):
        query = input()
        if query == "1":
            is_turned = not is_turned
        else:
            T, F, C = query.split()
            if is_turned ^ (F == "1"):
                S = C + S
            else:
                S = S + C

    if (is_turned):
        print(S[::-1])
    else:
        print(S)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    S = input()
    Q = int(input())
    L = ""
    R = ""
    is_turned = False

    for _ in range(Q):
        Query = input().split()
        if Query[0] == "1":
            is_turned = not is_turned
        else:
            if is_turned ^ (Query[1] == "1"):
                # L.insert(0, Query[2])
                L = Query[2] + L
            else:
                # R.append(Query[2])
                R = R + Query[2]

    if (is_turned):
        print("".join(L + S + R)[::-1])
    else:
        print("".join(L + S + R))


if __name__ == "__main__":
    main()