Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
Q = int(input())
not_reversed = True
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        not_reversed = not not_reversed 
        continue
    
    else:
        if not_reversed == 1 and query[1] == "1":
            S = query[2] + S

        elif not not_reversed == -1 and query[1] == "1":
            S = S + query[2]

        if not_reversed == 1 and query[1] == "2":
            S = S + query[2]
            
        elif not not_reversed == -1 and query[1] == "2":
            S = query[2] + S

if not_reversed == False:
    S = list(S)
    S.reverse()
    print("".join(map(str, S)))
else:
    print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
Q = int(input())
add_left = ""
add_right = ""
not_reversed = True
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        not_reversed = not not_reversed 
        continue
    
    else:
        if not_reversed == 1 and query[1] == "1":
            add_left = query[2] + add_left

        elif not not_reversed == -1 and query[1] == "1":
            add_right = add_right + query[2]

        if not_reversed == 1 and query[1] == "2":
            add_right = add_right + query[2]
            
        elif not not_reversed == -1 and query[1] == "2":
            add_left = query[2] + add_left

if not_reversed == False:
    ans = list(add_left) + list(S) + list(add_right)
    ans.reverse()
    print("".join(map(str, ans)))
else:
    ans = add_left + S + add_right
    print(ans)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
Q = int(input())

for _ in range(Q):
    query = deque(input().split())
    if query[0] == "1":
        S = list(S)
        S.reverse()
        S = "".join(map(str, S))
    elif query[1] == "1":
        S = query[2] + S
    elif query[1] == "2":
        S = S + query[2]

print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Buggy python submission (verdict: Runtime Error):
def main():
    from collections import deque
    S = input()
    Q = int(input())

    for _ in range(Q):
        query = deque(input().split())
        if query[0] == "1":
            S.reverse()
        elif query[1] == "1":
            S = query[2] + S
        elif query[1] == "2":
            S = S + query[2]

    print("".join(map(str, S)))

if __name__ == "__main__":
    main()

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Buggy python submission (verdict: Runtime Error):
def main():
    from collections import deque
    S = input()
    Q = int(input())

    for _ in range(Q):
        query = deque(input().split())
        if query[0] == "1":
            S.reverse()
        elif query[1] == "1":
            S = query[2] + S
        elif query[1] == "2":
            S = S + query[2]

    print("".join(map(str, S)))

if __name__ == "__main__":
    main()

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from collections import deque
    S = deque(list(input()))
    Q = int(input())

    for _ in range(Q):
        query = deque(input().split())
        if query[0] == "1":
            S.reverse()
        elif query[1] == "1":
            S.appendleft(query[2])
        elif query[1] == "2" :
            S.append(query[2])

    print("".join(map(str, S)))

if __name__ == "__main__":
    main()

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = deque(list(input()))
Q = int(input())

for q in range(Q):
    query = list(input().split())
    if query[0] == "1":
        S.reverse()
    elif query[1] == "1":
        S.appendleft(query[2])
    elif query[1] == "2" :
        S.append(query[2])

print("".join(map(str, S)))

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
is_reversed = 1
for _ in range(Q):
    query = list(input().split())
    if query[0] == "1":
        is_reversed *= -1
    
    else:
        if is_reversed == 1:
            if query[1] == "1":
                S.appendleft(query[2])
            else:
                S.append(query[2])
        else:
            if query[1] == "2":
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = "".join(S)
print(S[::is_reversed])