Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if flag:
                s.reverse()
                flag = False
            if temp[1] == "1":
                appendleft(temp[2])
            else:
                append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()


Fixed submission:
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if temp[1] == "1":
                if flag:
                    append(temp[2])
                else:
                    appendleft(temp[2])
            else:
                if flag:
                    appendleft(temp[2])
                else:
                    append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
q = int(input())
work = deque()
workappendleft = work.appendleft
appendleft=s.appendleft
append=s.append
flag = False
for i in range(q):
    temp = input().split()
    if temp[0] == "1":
        flag = not flag
    else:
        if flag:
            for el in s:
                workappendleft(el)
            s.clear()
            for el in work:
                append(el)
            work.clear()
            flag = False
        if temp[1] == "1":
            appendleft(temp[2])
        else:
            append(temp[2])
if flag:
    for el in s:
        workappendleft(el)
    s.clear()
    for el in work:
        append(el)
print("".join(list(s)))


Fixed submission:
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if temp[1] == "1":
                if flag:
                    append(temp[2])
                else:
                    appendleft(temp[2])
            else:
                if flag:
                    appendleft(temp[2])
                else:
                    append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
q = int(input())
work = deque()
workappendleft = work.appendleft
appendleft=s.appendleft
append=s.append
for i in range(q):
    temp = input().split()
    if temp[0] == "1":
        for el in s:
            workappendleft(el)
        s.clear()
        for el in work:
            append(el)
        work.clear()
    else:
        if temp[1] == "1":
            appendleft(temp[2])
        else:
            append(temp[2])
print("".join(list(s)))

Fixed submission:
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if temp[1] == "1":
                if flag:
                    append(temp[2])
                else:
                    appendleft(temp[2])
            else:
                if flag:
                    appendleft(temp[2])
                else:
                    append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
q = int(input())
work = deque()
workappendleft = work.appendleft
appendleft=s.appendleft
append=s.append
for i in range(q):
    temp = input().split()
    t = temp[0]
    if t == "1":
        for el in s:
            workappendleft(el)
        s.clear()
        for el in work:
            append(el)
        work.clear()
    else:
        f = temp[1]
        c = temp[2]
        if f == "1":
            appendleft(c)
        else:
            append(c)
print("".join(list(s)))

Fixed submission:
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if temp[1] == "1":
                if flag:
                    append(temp[2])
                else:
                    appendleft(temp[2])
            else:
                if flag:
                    appendleft(temp[2])
                else:
                    append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
q = int(input())
appendleft=s.appendleft
append=s.append
for i in range(q):
    temp = input().split()
    t = temp[0]
    if t == "1":
        work = deque()
        for el in s:
            work.appendleft(el)
        s.clear()
        for el in work:
            append(el)
    else:
        f = temp[1]
        c = temp[2]
        if f == "1":
            appendleft(c)
        else:
            append(c)
print("".join(list(s)))

Fixed submission:
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if temp[1] == "1":
                if flag:
                    append(temp[2])
                else:
                    appendleft(temp[2])
            else:
                if flag:
                    appendleft(temp[2])
                else:
                    append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    temp = input().split()
    t = temp[0]
    if t == "1":
        s = s[::-1]
    else:
        f = temp[1]
        c = temp[2]
        if f == "1":
            s = c + s
        else:
            s = s + c
print(s)

Fixed submission:
from collections import deque
def main():
    s = deque(input())
    q = int(input())
    appendleft=s.appendleft
    append=s.append
    flag = False
    for i in range(q):
        temp = input().split()
        if temp[0] == "1":
            flag = not flag
        else:
            if temp[1] == "1":
                if flag:
                    append(temp[2])
                else:
                    appendleft(temp[2])
            else:
                if flag:
                    appendleft(temp[2])
                else:
                    append(temp[2])
    if flag:
        s.reverse()
    print("".join(list(s)))
if __name__=="__main__":
    main()