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

jun = True

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            S = T[2] + S
            continue

        else:
            S = S + T[2]

if jun:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = input()
Q = int(input())

jun = True
head = ""

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            head += T[2]
            continue

        else:
            S += T[2]

if jun:
    print(head[::-1] + S)
else:
    print(S[::-1] + head)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())

jun = True

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            S = T[2] + S
            continue

        else:
            (T[1] == "2" and jun) or (T[1] == "1" and not jun):
            S = S + T[2]

if jun:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = input()
Q = int(input())

jun = True
head = ""

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            head += T[2]
            continue

        else:
            S += T[2]

if jun:
    print(head[::-1] + S)
else:
    print(S[::-1] + head)

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

jun = True

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun

    if T[0] == "2" and ((T[1] == "1" and jun) or (T[1] == "2" and not jun)):
        S = T[2] + S
        continue
        
    if T[0] == "2" and ((T[1] == "2" and jun) or (T[1] == "1" and not jun)):
        S = S + T[2]

if jun:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = input()
Q = int(input())

jun = True
head = ""

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            head += T[2]
            continue

        else:
            S += T[2]

if jun:
    print(head[::-1] + S)
else:
    print(S[::-1] + head)

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

jun = True

for _ in range(Q):
    tmpS = S
    T = input().split()
    if T[0] == "1":
        jun = not jun

    if T[0] == "2" and ((T[1] == "1" and jun) or (T[1] == "2" and not jun)):
        S = T[2] + tmpS
        continue
        
    if T[0] == "2" and ((T[1] == "2" and jun) or (T[1] == "1" and not jun)):
        S = tmpS + T[2]

if jun:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = input()
Q = int(input())

jun = True
head = ""

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            head += T[2]
            continue

        else:
            S += T[2]

if jun:
    print(head[::-1] + S)
else:
    print(S[::-1] + head)

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

jun = True

for _ in range(Q):
    tmpS = S
    T = input().split()
    if T[0] == "1":
        jun = not jun
    if T[0] == "2":
        if T[1] == "1":
            S = T[2] + tmpS if jun else tmpS + T[2]
        if T[1] == "2":
            S = tmpS + T[2] if jun else T[2] + tmpS
if jun:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = input()
Q = int(input())

jun = True
head = ""

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            head += T[2]
            continue

        else:
            S += T[2]

if jun:
    print(head[::-1] + S)
else:
    print(S[::-1] + head)

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

for _ in range(Q):
    tmpS = S
    T = input().split()
    if T[0] == "1":
        S = tmpS[::-1]
    if T[0] == "2":
        if T[1] == "1":
            S = T[2] + tmpS
        if T[1] == "2":
            S = tmpS + T[2]

print(S)

Fixed submission:
S = input()
Q = int(input())

jun = True
head = ""

for _ in range(Q):
    T = input().split()
    if T[0] == "1":
        jun = not jun
    
    else:

        if (T[1] == "1" and jun) or (T[1] == "2" and not jun):
            head += T[2]
            continue

        else:
            S += T[2]

if jun:
    print(head[::-1] + S)
else:
    print(S[::-1] + head)