Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    q = int(input())
    for _ in range(q):
        inp = input()
        if inp == "1":
            s = s[::-1]
        else:
            z = inp.split()
            b = int(z[1])
            c = z[2]
            if b == 1:
                s = "".join([c, s])
            else:
                s = "".join([s, c])
    print(s)
resolve()

Fixed submission:
def resolve():
    from collections import deque
    s = deque(input())
    q = int(input())
    qlist = [input().split() for i in range(q)]
    flip = False
    for j in range(q):
        if qlist[j][0] == "1":
            flip = not flip
        elif qlist[j][1] == "1":
            if flip:
                s.append(qlist[j][2])
            else:
                s.appendleft(qlist[j][2])
        elif qlist[j][1] == "2":
            if flip:
                s.appendleft(qlist[j][2])
            else:
                s.append(qlist[j][2])
    if not flip:
        print("".join(s))
    else:
        s.reverse()
        print("".join(s))
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    q = int(input())
    for _ in range(q):
        inp = input()
        if inp == "1":
            s = s[::-1]
        else:
            z = inp.split()
            b = int(z[1])
            c = z[2]
            if b == 1:
                s = "".join([c, s])
            else:
                s = "".join([s, c])
    print(s)
resolve()

Fixed submission:
def resolve():
    from collections import deque
    s = deque(input())
    q = int(input())
    qlist = [input().split() for i in range(q)]
    flip = False
    for j in range(q):
        if qlist[j][0] == "1":
            flip = not flip
        elif qlist[j][1] == "1":
            if flip:
                s.append(qlist[j][2])
            else:
                s.appendleft(qlist[j][2])
        elif qlist[j][1] == "2":
            if flip:
                s.appendleft(qlist[j][2])
            else:
                s.append(qlist[j][2])
    if not flip:
        print("".join(s))
    else:
        s.reverse()
        print("".join(s))
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    q = int(input())
    qall = []
    for _ in range(q):
        inp = input()
        if inp == "1":
            s = s[::-1]
        else:
            z = inp.split()
            b = int(z[1])
            c = z[2]
            if b == 1:
                s = c + s
            else:
                s = s + c
    print(s)
resolve()

Fixed submission:
def resolve():
    from collections import deque
    s = deque(input())
    q = int(input())
    qlist = [input().split() for i in range(q)]
    flip = False
    for j in range(q):
        if qlist[j][0] == "1":
            flip = not flip
        elif qlist[j][1] == "1":
            if flip:
                s.append(qlist[j][2])
            else:
                s.appendleft(qlist[j][2])
        elif qlist[j][1] == "2":
            if flip:
                s.appendleft(qlist[j][2])
            else:
                s.append(qlist[j][2])
    if not flip:
        print("".join(s))
    else:
        s.reverse()
        print("".join(s))
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    q = int(input())
    qall = []
    for _ in range(q):
        qall.append(input())

    for i in range(q):
        if qall[i] == "1":
            s = s[::-1]
        else:
            z = qall[i].split()
            b = int(z[1])
            c = z[2]
            if b == 1:
                s = c + s
            else:
                s = s + c
    print(s)
resolve()

Fixed submission:
def resolve():
    from collections import deque
    s = deque(input())
    q = int(input())
    qlist = [input().split() for i in range(q)]
    flip = False
    for j in range(q):
        if qlist[j][0] == "1":
            flip = not flip
        elif qlist[j][1] == "1":
            if flip:
                s.append(qlist[j][2])
            else:
                s.appendleft(qlist[j][2])
        elif qlist[j][1] == "2":
            if flip:
                s.appendleft(qlist[j][2])
            else:
                s.append(qlist[j][2])
    if not flip:
        print("".join(s))
    else:
        s.reverse()
        print("".join(s))
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    q = int(input())
    qall = []
    for _ in range(q):
        inp = input()
        if inp == "1":
            s = s[::-1]
        else:
            z = inp.split()
            b = int(z[1])
            c = z[2]
            if b == 1:
                s = c + s
            else:
                s = s + c
    print(s)
resolve()

Fixed submission:
def resolve():
    from collections import deque
    s = deque(input())
    q = int(input())
    qlist = [input().split() for i in range(q)]
    flip = False
    for j in range(q):
        if qlist[j][0] == "1":
            flip = not flip
        elif qlist[j][1] == "1":
            if flip:
                s.append(qlist[j][2])
            else:
                s.appendleft(qlist[j][2])
        elif qlist[j][1] == "2":
            if flip:
                s.appendleft(qlist[j][2])
            else:
                s.append(qlist[j][2])
    if not flip:
        print("".join(s))
    else:
        s.reverse()
        print("".join(s))
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s = input()
    q = int(input())
    qall = []
    for _ in range(q):
        inp = input()
        if inp == "1":
            s = s[::-1]
        else:
            z = inp.split()
            a = int(z[0])
            b = int(z[1])
            c = z[2]
            if b == 1:
                s = s[::-1]
                s = s + c
                s = s[::-1]
            else:
                s = s + c
    print(s)
resolve()

Fixed submission:
def resolve():
    from collections import deque
    s = deque(input())
    q = int(input())
    qlist = [input().split() for i in range(q)]
    flip = False
    for j in range(q):
        if qlist[j][0] == "1":
            flip = not flip
        elif qlist[j][1] == "1":
            if flip:
                s.append(qlist[j][2])
            else:
                s.appendleft(qlist[j][2])
        elif qlist[j][1] == "2":
            if flip:
                s.appendleft(qlist[j][2])
            else:
                s.append(qlist[j][2])
    if not flip:
        print("".join(s))
    else:
        s.reverse()
        print("".join(s))
resolve()