Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                T = que[4]+S
            else:
                T = S+que[4]
        else:
            if flag:
                T = S+que[4]
            else:
                T = que[4]+S
        S = T
if flag:
    print(S)
else:
    for i in range(len(S)):
        print(S[len(S)-i-1], end = '')
    print()


Fixed submission:
S = input()
T = ''
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                T = T+que[4]
            else:
                S = S+que[4]
        else:
            if flag:
                S = S+que[4]
            else:
                T = T+que[4]
if flag:
    U = ''
    for i in range(len(T)):
        U += T[len(T)-i-1]
    print(U+S)
else:
    U = ''
    for i in range(len(S)):
        U += S[len(S)-i-1]
    print(U+T)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                S = ''.join([que[4], S])
            else:
                S = ''.join([S, que[4]])
        else:
            if flag:
                S = ''.join([S, que[4]])
            else:
                S = ''.join([que[4], S])
if flag:
    print(S)
else:
    for i in range(len(S)):
        print(S[len(S)-i-1], end = '')
    print()


Fixed submission:
S = input()
T = ''
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                T = T+que[4]
            else:
                S = S+que[4]
        else:
            if flag:
                S = S+que[4]
            else:
                T = T+que[4]
if flag:
    U = ''
    for i in range(len(T)):
        U += T[len(T)-i-1]
    print(U+S)
else:
    U = ''
    for i in range(len(S)):
        U += S[len(S)-i-1]
    print(U+T)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                S = que[4]+S
            else:
                S = S+que[4]
        else:
            if flag:
                S = S+que[4]
            else:
                S = que[4]+S
if flag:
    print(S)
else:
    for i in range(len(S)):
        print(S[len(S)-i-1], end = '')
    print()

Fixed submission:
S = input()
T = ''
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                T = T+que[4]
            else:
                S = S+que[4]
        else:
            if flag:
                S = S+que[4]
            else:
                T = T+que[4]
if flag:
    U = ''
    for i in range(len(T)):
        U += T[len(T)-i-1]
    print(U+S)
else:
    U = ''
    for i in range(len(S)):
        U += S[len(S)-i-1]
    print(U+T)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                S = que[4]+S
            else:
                S = S+que[4]
        else:
            if flag:
                S = S+que[4]
            else:
                S = que[4]+S
if flag:
    print(S)
else:
    for i in range(len(S)):
        print(S[len(S)-i-1], end = '')
    print()

Fixed submission:
S = input()
T = ''
Q = int(input())
flag = True
for i in range(Q):
    que = input()
    if len(que) == 1:
        if flag:
            flag = False
        else:
            flag = True
    else:
        if que[2] == '1':
            if flag:
                T = T+que[4]
            else:
                S = S+que[4]
        else:
            if flag:
                S = S+que[4]
            else:
                T = T+que[4]
if flag:
    U = ''
    for i in range(len(T)):
        U += T[len(T)-i-1]
    print(U+S)
else:
    U = ''
    for i in range(len(S)):
        U += S[len(S)-i-1]
    print(U+T)