Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    queries = [input().split() for i in range(q)]

    flg = True
    for query in queries:
        if "1" == query[0]:
            flg = not flg
        elif "2" == query[0]:
            if ("1" == query[1] and flg) or ("2" == query[1] and not flg):
                s = query[2] + s
            else:
                s += query[2]

    if flg:
        print(s)
    else:
        print(s[::-1])


if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    queries = (input().split() for i in range(q))

    flg = True
    result = s
    pre = ""
    post = ""
    for query in queries:
        if "1" == query[0]:
            flg = not flg
        elif "2" == query[0]:
            if ("1" == query[1] and flg) or ("2" == query[1] and not flg):
                pre = query[2] + pre
            else:
                post += query[2]

    if flg:
        print(pre + result + post)
    else:
        print((pre + result + post)[::-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    queries = [input().split() for i in range(q)]

    for query in queries:
        if "1" == query[0]:
            s = s[::-1]
        elif "2" == query[0]:
            if "1" == query[1]:
                s = query[2] + s
            elif "2" == query[1]:
                s += query[2]

    print(s)


if __name__ == '__main__':
    main()

Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    queries = (input().split() for i in range(q))

    flg = True
    result = s
    pre = ""
    post = ""
    for query in queries:
        if "1" == query[0]:
            flg = not flg
        elif "2" == query[0]:
            if ("1" == query[1] and flg) or ("2" == query[1] and not flg):
                pre = query[2] + pre
            else:
                post += query[2]

    if flg:
        print(pre + result + post)
    else:
        print((pre + result + post)[::-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
s = input()
q = int(input())

queries = [input().split() for i in range(q)]

for query in queries:
    if "1" == query[0]:
        s = s[::-1]
    elif "2" == query[0]:
        if "1" == query[1]:
            s = query[2] + s
        elif "2" == query[1]:
            s += query[2]

print(s)


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    queries = (input().split() for i in range(q))

    flg = True
    result = s
    pre = ""
    post = ""
    for query in queries:
        if "1" == query[0]:
            flg = not flg
        elif "2" == query[0]:
            if ("1" == query[1] and flg) or ("2" == query[1] and not flg):
                pre = query[2] + pre
            else:
                post += query[2]

    if flg:
        print(pre + result + post)
    else:
        print((pre + result + post)[::-1])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
s = input()
q = int(input())

queries = [input().split() for i in range(q)]

for query in queries:
    if "1" == query[0]:
        s = s[::-1]
    elif "2" == query[0]:
        if "1" == query[1]:
            s = query[2] + s
        elif "2" == query[1]:
            s += query[2]

print(s)


Fixed submission:
# -*- coding: utf-8 -*-


def main():
    s = input()
    q = int(input())

    queries = (input().split() for i in range(q))

    flg = True
    result = s
    pre = ""
    post = ""
    for query in queries:
        if "1" == query[0]:
            flg = not flg
        elif "2" == query[0]:
            if ("1" == query[1] and flg) or ("2" == query[1] and not flg):
                pre = query[2] + pre
            else:
                post += query[2]

    if flg:
        print(pre + result + post)
    else:
        print((pre + result + post)[::-1])


if __name__ == '__main__':
    main()