Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
cnt = 0
for q in qry:
    if q[0] == '1':
        cnt += 1
        if oq == '1':
            continue
        A, B = B[::-1], A[::-1]
    else:
        if q[1] == '1':
            A = q[2] + A
        else:
            B += q[2]

if cnt % 2 == 1:
    S = S[::-1]

print(A + S + B)


Fixed submission:
S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])

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


Fixed submission:
S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])

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


Fixed submission:
S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])

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


Fixed submission:
S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
Qry = [input().split() for i in range(Q)]
for q in Qry:
    if q[0] == '1':
        S.reverse()
    else:
        if q[1] == '1':
            S = [q[2]] + S
        else:
            S += [q[2]]
print(*S, sep='')


Fixed submission:
S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
Qry = [input().split() for i in range(Q)]
for q in Qry:
    if q[0] == '1':
        #S = [S[-1]] + S[1:-1] + [S[0]]
        S = S[::-1]
    else:
        if q[1] == '1':
            S = [q[2]] + S
        else:
            S += [q[2]]
print(*S, sep='')


Fixed submission:
S = input()
Q = int(input())
qry = [input().split() for _ in range(Q)]
A = ''
B = ''
oq = 0
even = True
for q in qry:
    if q[0] == '1':
        even = not even
        if oq == '1':
            continue
    else:
        if even:
            if q[1] == '1':
                A = q[2] + A
            else:
                B += q[2]
        else:
            if q[1] == '1':
                B += q[2]
            else:
                A = q[2] + A
    oq = q

if even:
    print(A+S+B)
else:
    print(B[::-1]+S[::-1]+A[::-1])