Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
count = 0
right = ''
left = ''
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        count += 1
    else:
        if arr[1] == '1':
            if count%2==0:
                S = arr[2] + S
            else:
                S = S + arr[2]
        else:
            if count%2!=0:
                S = arr[2] + S
            else:
                S = S + arr[2]
if count%2 == 0:
    print(S)
else:
    ans = ''
    for i in S:
        ans = i + ans
    print(ans)

Fixed submission:
S = input()
Q = int(input())
count = 0
right = ''
left = ''
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        count += 1
    else:
        if arr[1] == '1':
            if count%2==0:
                left = arr[2] + left
            else:
                right = right + arr[2]
        else:
            if count%2!=0:
                left = arr[2] + left
            else:
                right = right + arr[2]
S = left + S + right
if count%2 == 0:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
count = 0
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        count += 1
    else:
        if arr[1] == '1':
            if count%2==0:
                S = arr[2] + S
            else:
                S = S + arr[2]
        else:
            if count%2!=0:
                S = arr[2] + S
            else:
                S = S + arr[2]
if count%2 == 0:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = input()
Q = int(input())
count = 0
right = ''
left = ''
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        count += 1
    else:
        if arr[1] == '1':
            if count%2==0:
                left = arr[2] + left
            else:
                right = right + arr[2]
        else:
            if count%2!=0:
                left = arr[2] + left
            else:
                right = right + arr[2]
S = left + S + right
if count%2 == 0:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
count = 0
left = ''
right = ''
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        left,right=right[::-1],left[::-1]
        count += 1
    else:
        if arr[1] == '1':
            left = arr[2] + left
        else:
            right = right + arr[2]
if count%2 == 0:
    print(left+S+right)
else:
    print(left+S[::-1]+right)

Fixed submission:
S = input()
Q = int(input())
count = 0
right = ''
left = ''
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        count += 1
    else:
        if arr[1] == '1':
            if count%2==0:
                left = arr[2] + left
            else:
                right = right + arr[2]
        else:
            if count%2!=0:
                left = arr[2] + left
            else:
                right = right + arr[2]
S = left + S + right
if count%2 == 0:
    print(S)
else:
    print(S[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        S = S[::-1]
    else:
        if arr[1] == '1':
            S = arr[2] + S
        else:
            S = S + arr[2]
print(S)

Fixed submission:
S = input()
Q = int(input())
count = 0
right = ''
left = ''
for i in range(Q):
    arr = list(input().split())
    if len(arr) == 1:
        count += 1
    else:
        if arr[1] == '1':
            if count%2==0:
                left = arr[2] + left
            else:
                right = right + arr[2]
        else:
            if count%2!=0:
                left = arr[2] + left
            else:
                right = right + arr[2]
S = left + S + right
if count%2 == 0:
    print(S)
else:
    print(S[::-1])