Buggy python submission (verdict: Runtime Error):
B = input()
order = True
F = ""
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        order ^= True
    else:
        f,c = T[1],T[2]
        if not((f == "1") ^ order):
            F += c
        else:
            B += c
    print(F,B)
F = F[::-1]+B
if not order:
    F = F[::-1]
print(F)

Fixed submission:
B = input()
order = True
F = ""
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        order ^= True
    else:
        f,c = T[1],T[2]
        if not((f == "1") ^ order):
            F += c
        else:
            B += c
    #print(F,B)
F = F[::-1]+B
if not order:
    F = F[::-1]
print(F)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        S = S[::-1]
    else:
        F,C = T[1],T[2]
        if F == "1":
            S = [C] + S
        else:
            S += [C]
print("".join(S))

Fixed submission:
B = input()
order = True
F = ""
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        order ^= True
    else:
        f,c = T[1],T[2]
        if not((f == "1") ^ order):
            F += c
        else:
            B += c
    #print(F,B)
F = F[::-1]+B
if not order:
    F = F[::-1]
print(F)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        S = S[::-1]
    else:
        F,C = T[1],T[2]
        if F == "1":
            S = [C] + S
        else:
            S += [C]
print("".join(S))

Fixed submission:
B = input()
order = True
F = ""
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        order ^= True
    else:
        f,c = T[1],T[2]
        if not((f == "1") ^ order):
            F += c
        else:
            B += c
    #print(F,B)
F = F[::-1]+B
if not order:
    F = F[::-1]
print(F)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        S = S[::-1]
    else:
        F,C = T[1],T[2]
        if F == "1":
            S = C + S
        else:
            S += C
print(S)

Fixed submission:
B = input()
order = True
F = ""
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        order ^= True
    else:
        f,c = T[1],T[2]
        if not((f == "1") ^ order):
            F += c
        else:
            B += c
    #print(F,B)
F = F[::-1]+B
if not order:
    F = F[::-1]
print(F)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        S = S[::-1]
    else:
        F,C = T[1],T[2]
        if F == "1":
            S = C + S
        else:
            S += C
print(S)

Fixed submission:
B = input()
order = True
F = ""
for q in range(int(input())):
    T = input().rstrip().split()
    if T[0] == "1":
        order ^= True
    else:
        f,c = T[1],T[2]
        if not((f == "1") ^ order):
            F += c
        else:
            B += c
    #print(F,B)
F = F[::-1]+B
if not order:
    F = F[::-1]
print(F)