Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    d = input()
    n = int(input())
    for _ in range(n):
        q = input()
        d = d[::-1] if q[0] == ('1') else q[-1]+d if q[:3] == ("2 1") else d+q[-1]
    print(d)

Fixed submission:
if __name__ == '__main__':
    d = input()
    n = int(input())
    qs = [input() for e in range(n)]
    s = []
    e = []
    r = False
    for q in qs:
        if q == '1':
            r = not(r)
        elif q.startswith("2 1"):
            e.append(q[-1]) if r else s.append(q[-1])
        else:
            s.append(q[-1]) if r else e.append(q[-1])
    print("".join(e[::-1]) + d[::-1] + "".join(s) if r else "".join(s[::-1]) + d + "".join(e))

Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    d = input()
    n = int(input())
    for _ in range(n):
        q = input()
        d = d[::-1] if q[0] == ('1') else d = q[-1]+d if q[:3] == ("2 1") else d=d+q[-1]      
    print(d)

Fixed submission:
if __name__ == '__main__':
    d = input()
    n = int(input())
    qs = [input() for e in range(n)]
    s = []
    e = []
    r = False
    for q in qs:
        if q == '1':
            r = not(r)
        elif q.startswith("2 1"):
            e.append(q[-1]) if r else s.append(q[-1])
        else:
            s.append(q[-1]) if r else e.append(q[-1])
    print("".join(e[::-1]) + d[::-1] + "".join(s) if r else "".join(s[::-1]) + d + "".join(e))

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    d = input()
    n = int(input())
    for _ in range(n):
        q = input()
        if q[0] == ('1'):
            d = d[::-1]
        elif q[:3] == ("2 1"):
            d = q[-1]+d
        elif q[:3] == ("2 2"):
            d=d+q[-1]
    print(d)

Fixed submission:
if __name__ == '__main__':
    d = input()
    n = int(input())
    qs = [input() for e in range(n)]
    s = []
    e = []
    r = False
    for q in qs:
        if q == '1':
            r = not(r)
        elif q.startswith("2 1"):
            e.append(q[-1]) if r else s.append(q[-1])
        else:
            s.append(q[-1]) if r else e.append(q[-1])
    print("".join(e[::-1]) + d[::-1] + "".join(s) if r else "".join(s[::-1]) + d + "".join(e))

Buggy python submission (verdict: Time Limit Exceeded):

if __name__ == '__main__':
    d = input()
    n = int(input())
    for _ in range(n):
        q = input()
        if q == '': break
        elif q.startswith('1'):
            d = d[::-1]
        elif q.startswith("2 1"):
            d = q[-1]+d
        elif q.startswith("2 2"):
            d=d+q[-1]
    print(d)

Fixed submission:
if __name__ == '__main__':
    d = input()
    n = int(input())
    qs = [input() for e in range(n)]
    s = []
    e = []
    r = False
    for q in qs:
        if q == '1':
            r = not(r)
        elif q.startswith("2 1"):
            e.append(q[-1]) if r else s.append(q[-1])
        else:
            s.append(q[-1]) if r else e.append(q[-1])
    print("".join(e[::-1]) + d[::-1] + "".join(s) if r else "".join(s[::-1]) + d + "".join(e))

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    s = input()
    n = int(input())
    for _ in range(n):
        q = input().split()
        if q[0] == '1':
            s = s[::-1]
        else:
            if q[1] == '1':
                s = q[2]+s
            elif q[1] == '2':
                s = s+q[2]
    print(s)

Fixed submission:
if __name__ == '__main__':
    d = input()
    n = int(input())
    qs = [input() for e in range(n)]
    s = []
    e = []
    r = False
    for q in qs:
        if q == '1':
            r = not(r)
        elif q.startswith("2 1"):
            e.append(q[-1]) if r else s.append(q[-1])
        else:
            s.append(q[-1]) if r else e.append(q[-1])
    print("".join(e[::-1]) + d[::-1] + "".join(s) if r else "".join(s[::-1]) + d + "".join(e))