Buggy python submission (verdict: Time Limit Exceeded):
# 文字列の操作だけでできるか

S = input()
Q = int(input())

T = 0
for i in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        # T = T ^ 1 (排他的論理和; 0 XOR 1 = 1, 1 XOR 1 = 0)
        T ^= 1
    elif T == 0:
        s = Query[2]
        if Query[1] == '1':
            S = s + S
        else:
            S = S + s
    else:
        s = Query[2]
        if Query[1] == '1':
            S = S + s
        else:
            S = s + S

if T == 1:
    S = S[::-1]

print(S)


Fixed submission:
# キューを使ったアプローチ

from collections import deque

S = deque(input())
Q = int(input())

T = 0
for _ in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T ^= 1
    elif T == 0:
        m = Query[2]
        if Query[1] == '1':
            S.appendleft(m)
        else:
            S.append(m)
    else:
        m = Query[2]
        if Query[1] == '2':
            S.appendleft(m)
        else:
            S.append(m)

if T==1:
    S.reverse()

print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):

S = list(input())
Q = int(input())

tmplist = []
T = 0
for i in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T = T+1
    else:
        if T%2 == 0:
            if Query[1] == '1':
                S.insert(0,Query[2])
            else:
                S.append(Query[2])
        else:
            if Query[1] == '2':
                S.insert(0,Query[2])
            else:
                S.append(Query[2])
#    print("len(Query)={}, Query={}, T={}, S={}".format(len(Query), Query,T,''.join(S)))

if T%2 == 1:
    #S.reverse()
    S=S[::-1]

#print("ans={}".format(''.join(S)))
print(''.join(S))


Fixed submission:
# キューを使ったアプローチ

from collections import deque

S = deque(input())
Q = int(input())

T = 0
for _ in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T ^= 1
    elif T == 0:
        m = Query[2]
        if Query[1] == '1':
            S.appendleft(m)
        else:
            S.append(m)
    else:
        m = Query[2]
        if Query[1] == '2':
            S.appendleft(m)
        else:
            S.append(m)

if T==1:
    S.reverse()

print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):

S = list(input())
Q = int(input())

tmplist = []
T = 0
for i in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T = T+1
    else:
        if T%2 == 0:
            if Query[1] == '1':
                S.insert(0,Query[2])
            else:
                S.append(Query[2])
        else:
            if Query[1] == '2':
                S.insert(0,Query[2])
            else:
                S.append(Query[2])
#    print("len(Query)={}, Query={}, T={}, S={}".format(len(Query), Query,T,''.join(S)))

if T%2 == 1:
    S.reverse()

#print("ans={}".format(''.join(S)))
print(''.join(S))


Fixed submission:
# キューを使ったアプローチ

from collections import deque

S = deque(input())
Q = int(input())

T = 0
for _ in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T ^= 1
    elif T == 0:
        m = Query[2]
        if Query[1] == '1':
            S.appendleft(m)
        else:
            S.append(m)
    else:
        m = Query[2]
        if Query[1] == '2':
            S.appendleft(m)
        else:
            S.append(m)

if T==1:
    S.reverse()

print(''.join(S))