Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = sys.stdin.readline().rstrip()
Q = int(sys.stdin.readline().rstrip())
flip = False

for i in range(Q):
    Que = sys.stdin.readline().rstrip()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        if (F == "1") ^ flip:
            S = "".join([Query[2], S])
        else:
            S = "".join([S, Query[2]])
print(S if not flip else S[::-1])


Fixed submission:
import sys
from collections import deque

S = deque(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())
flip = False

for i in range(Q):
    Que = sys.stdin.readline().rstrip()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        if (F == "1") ^ flip:
            S.appendleft(Query[2])
        else:
            S.append(Query[2])
print("".join(S) if not flip else "".join(S)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
flip = False

for i in range(Q):
    Que = input()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        C = Query[2]
        if (F == "1" and not flip) or (F == "2" and flip):
            S = "".join([C, S])
        else:
            S = "".join([S, C])
print(S if not flip else S[::-1])


Fixed submission:
import sys
from collections import deque

S = deque(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())
flip = False

for i in range(Q):
    Que = sys.stdin.readline().rstrip()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        if (F == "1") ^ flip:
            S.appendleft(Query[2])
        else:
            S.append(Query[2])
print("".join(S) if not flip else "".join(S)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Que = [input().split(" ") for i in range(Q)]
flip = False

start = ""
end = ""

for i in Que:
    T = i[0]
    if T == "1":
        flip = not(flip)
    else:
        F = i[1]
        C = i[2]
        if (F == "1" and not flip) or (F == "2" and flip):
            S = "".join([C, S])
        else:
            S = "".join([S, C])
print(S if not flip else S[::-1])

Fixed submission:
import sys
from collections import deque

S = deque(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())
flip = False

for i in range(Q):
    Que = sys.stdin.readline().rstrip()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        if (F == "1") ^ flip:
            S.appendleft(Query[2])
        else:
            S.append(Query[2])
print("".join(S) if not flip else "".join(S)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Que = [input().split(" ") for i in range(Q)]
flip = False

for i in Que:
    T = int(i[0])
    if T == 1:
        flip = not(flip)
    else:
        F = int(i[1])
        C = i[2]
        if (F == 1 and not flip) or (F == 2 and flip):
            S = C + S
        else:
            S = S + C
print(S if not flip else S[::-1])


Fixed submission:
import sys
from collections import deque

S = deque(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())
flip = False

for i in range(Q):
    Que = sys.stdin.readline().rstrip()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        if (F == "1") ^ flip:
            S.appendleft(Query[2])
        else:
            S.append(Query[2])
print("".join(S) if not flip else "".join(S)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Que = [input().split(" ") for i in range(Q)]

for i in Que:
    T = int(i[0])
    if T == 1:
        S = S[::-1]
    else:
        F = int(i[1])
        C = i[2]
        if F == 1:
            S = C + S
        else:
            S = S + C
print(S)

Fixed submission:
import sys
from collections import deque

S = deque(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())
flip = False

for i in range(Q):
    Que = sys.stdin.readline().rstrip()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        if (F == "1") ^ flip:
            S.appendleft(Query[2])
        else:
            S.append(Query[2])
print("".join(S) if not flip else "".join(S)[::-1])