Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
hanten = 1
for _ in range(Q):
    q = list(map(str, input().split()))
    if q[0]=='1':
        hanten *= -1
    else:
        if hanten==1:
            if q[1]=='1':
                S = q[2] + S
            else:
                S = S + q[2]
        else:
            if q[1]=='1':
                S = S + q[2]
            else:
                S = q[2] + S

if hanten==1:
    print(S)
else:
    print(''.join(reversed(list(S))))

Fixed submission:
S = input()
Q = int(input())
hanten = 1
front = []
back = []
for _ in range(Q):
    q = list(map(str, input().split()))
    if q[0]=='1':
        hanten *= -1
    else:
        if hanten==1:
            if q[1]=='1':
                front.append(q[2])
            else:
                back.append(q[2])
        else:
            if q[1]=='1':
                back.append(q[2])
            else:
                front.append(q[2])


if hanten==1:
    print(''.join(list(reversed(front)) + list(S) + back))
else:
    print(''.join(list(reversed(list(S)+back))+front))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    q = list(map(str, input().split()))
    if len(q)==1:
        S = ''.join(reversed(list(S)))
    else:
        if q[1]=='1':
            S = ''.join([q[2], S])
        else:
            S = ''.join([S, q[2]])

print(S)

Fixed submission:
S = input()
Q = int(input())
hanten = 1
front = []
back = []
for _ in range(Q):
    q = list(map(str, input().split()))
    if q[0]=='1':
        hanten *= -1
    else:
        if hanten==1:
            if q[1]=='1':
                front.append(q[2])
            else:
                back.append(q[2])
        else:
            if q[1]=='1':
                back.append(q[2])
            else:
                front.append(q[2])


if hanten==1:
    print(''.join(list(reversed(front)) + list(S) + back))
else:
    print(''.join(list(reversed(list(S)+back))+front))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0]=='1':
        S = ''.join(reversed(list(S)))
    else:
        if query[1]=='1':
            S = query[2] + S
        else:
            S = S + query[2]

print(S)

Fixed submission:
S = input()
Q = int(input())
hanten = 1
front = []
back = []
for _ in range(Q):
    q = list(map(str, input().split()))
    if q[0]=='1':
        hanten *= -1
    else:
        if hanten==1:
            if q[1]=='1':
                front.append(q[2])
            else:
                back.append(q[2])
        else:
            if q[1]=='1':
                back.append(q[2])
            else:
                front.append(q[2])


if hanten==1:
    print(''.join(list(reversed(front)) + list(S) + back))
else:
    print(''.join(list(reversed(list(S)+back))+front))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for _ in range(Q):
    query = list(map(str, input().split()))
    if query[0]=='1':
        S.reverse()
    else:
        if query[1]=='1':
            S = list(query[2]) + S
        else:
            S = S + list(query[2])

print(''.join(S))

Fixed submission:
S = input()
Q = int(input())
hanten = 1
front = []
back = []
for _ in range(Q):
    q = list(map(str, input().split()))
    if q[0]=='1':
        hanten *= -1
    else:
        if hanten==1:
            if q[1]=='1':
                front.append(q[2])
            else:
                back.append(q[2])
        else:
            if q[1]=='1':
                back.append(q[2])
            else:
                front.append(q[2])


if hanten==1:
    print(''.join(list(reversed(front)) + list(S) + back))
else:
    print(''.join(list(reversed(list(S)+back))+front))