Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
quest = [0]*q
state = 0
# former, latter = '', ''
for i in range(q):
    que = input().split()
# for que in quest:
    if (que[0] == '1'):
        # 反転は計算量が多いので一度だけする。
        state = 1 - state
        continue
    else:
        if (state == 0 and que[1] == '1'):
            s = que[2] + s
        elif(state == 0 and que[1] == '2'):
            s = s + que[2]
        elif (state == 1 and que[1] == '1'):
            s = s + que[2]
        else:
            s = que[2] + s

if (state == 1):
    print(s[::-1])
else:
    print(s)


Fixed submission:
s = input()
q = int(input())
quest = [0]*q
state = 0
former, latter = '', ''
for i in range(q):
    que = input().split()
# for que in quest:
    if (que[0] == '1'):
        # 反転は計算量が多いので一度だけする。
        state = 1 - state
        continue
    else:
        if (state == 0 and que[1] == '1'):
            former = que[2] + former
        elif(state == 0 and que[1] == '2'):
            latter = latter + que[2]
        elif (state == 1 and que[1] == '1'):
            latter = latter + que[2]
        else:
            former = que[2] + former

if (state == 1):
    print(latter[::-1] + s[::-1] + former[::-1])
else:
    print(former + s + latter)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
quest = [0]*q
state = 0
for i in range(q):
    que = input().split()
# for que in quest:
    if (que[0] == '1'):
        # 反転は計算量が多いので一度だけする。
        state = 1 - state
        continue
    else:
        if (state == 0 and que[1] == '1'):
            s = que[2] + s
        elif(state == 0 and que[1] == '2'):
            s = s + que[2]
        elif (state == 1 and que[1] == '1'):
            s = s + que[2]
        else:
            s = que[2] + s

if (state == 1):
    s = s[::-1]
print(s)


Fixed submission:
s = input()
q = int(input())
quest = [0]*q
state = 0
former, latter = '', ''
for i in range(q):
    que = input().split()
# for que in quest:
    if (que[0] == '1'):
        # 反転は計算量が多いので一度だけする。
        state = 1 - state
        continue
    else:
        if (state == 0 and que[1] == '1'):
            former = que[2] + former
        elif(state == 0 and que[1] == '2'):
            latter = latter + que[2]
        elif (state == 1 and que[1] == '1'):
            latter = latter + que[2]
        else:
            former = que[2] + former

if (state == 1):
    print(latter[::-1] + s[::-1] + former[::-1])
else:
    print(former + s + latter)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
quest = [0]*q
for i in range(q):
    quest[i] = input().split()
state = 0
for que in quest:
    if (que[0] == '1'):
        # 反転は計算量が多いので一度だけする。
        state = 1 - state
        continue
    else:
        if (state == 0 and que[1] == '1'):
            s = que[2] + s
        elif(state == 0 and que[1] == '2'):
            s = s + que[2]
        elif (state == 1 and que[1] == '1'):
            s = s + que[2]
        else:
            s = que[2] + s

if (state == 1):
    s = s[::-1]
print(s)


Fixed submission:
s = input()
q = int(input())
quest = [0]*q
state = 0
former, latter = '', ''
for i in range(q):
    que = input().split()
# for que in quest:
    if (que[0] == '1'):
        # 反転は計算量が多いので一度だけする。
        state = 1 - state
        continue
    else:
        if (state == 0 and que[1] == '1'):
            former = que[2] + former
        elif(state == 0 and que[1] == '2'):
            latter = latter + que[2]
        elif (state == 1 and que[1] == '1'):
            latter = latter + que[2]
        else:
            former = que[2] + former

if (state == 1):
    print(latter[::-1] + s[::-1] + former[::-1])
else:
    print(former + s + latter)