Buggy python submission (verdict: Time Limit Exceeded):

s = input()
q = int(input())
ans = []
ans_s = ''
one_count = 0
key = 0
for i in range(q):
    ans.append(list(input().split()))
for i in ans:
    if int(i[0])==1:
        one_count += 1
    else:
        if one_count%2==0:
            if int(i[1]) == 1:
                #ans_q.insert(0,i[2])
                s = i[2]+s
                #ans_s = ans_s+i[2]
            else:
                s = s+i[2]
                #ans_q.insert(len(ans_q),i[2])
                #ans_s = i[2]+ans_s
                #key += 1
        else:
            if int(i[1]) == 1:
                #ans_q.insert(len(ans_q),i[2])
                s = s+i[2]
                #ans_s = i[2]+ans_s

            else:
                #ans_q.2insert(0,i[2])
                s = i[2]+s
                #ans_s = ans_s+i[2]

if one_count%2==0:
    print(s)
else:
    print(s[::-1])


Fixed submission:

from collections import deque
s = input()
q = int(input())
s = deque(s)
ans = []
ans_s = ''
one_count = 0
key = 0
for i in range(q):
    ans.append(list(input().split()))
for i in ans:
    if int(i[0])==1:
        one_count += 1
    else:
        if one_count%2==0:
            if int(i[1]) == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if int(i[1]) == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])

if one_count%2==0:
    print(''.join(s))
else:
    print(''.join(s)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):

s = input()
q = int(input())
ans = []
one_count = 0
for i in range(q):
    ans.append(list(input().split()))
for i in ans:
    if int(i[0])==1:
        one_count += 1
    else:
        if one_count%2==0:
            if int(i[1]) == 1:
                #ans_q.insert(0,i[2])
                s = i[2]+s
            else:
                s = s+i[2]
                #ans_q.insert(len(ans_q),i[2])
        else:
            if int(i[1]) == 1:
                #ans_q.insert(len(ans_q),i[2])
                s = s+i[2]
            else:
                #ans_q.2insert(0,i[2])
                s = i[2]+s
if one_count%2==0:
    print(s)
else:
    print(s[::-1])


Fixed submission:

from collections import deque
s = input()
q = int(input())
s = deque(s)
ans = []
ans_s = ''
one_count = 0
key = 0
for i in range(q):
    ans.append(list(input().split()))
for i in ans:
    if int(i[0])==1:
        one_count += 1
    else:
        if one_count%2==0:
            if int(i[1]) == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if int(i[1]) == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])

if one_count%2==0:
    print(''.join(s))
else:
    print(''.join(s)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ans_q = [s]
ans = []
one_count = 0
for i in range(q):
    ans.append(list(input().split()))
for i in ans:
    if int(i[0])==1:
        one_count += 1
    else:
        if one_count%2==0:
            if int(i[1]) == 1:
                ans_q.insert(0,i[2])
            else:
                ans_q.insert(len(ans_q),i[2])
        else:
            if int(i[1]) == 1:
                ans_q.insert(len(ans_q),i[2])
            else:
                ans_q.insert(0,i[2])
if one_count%2==0:
    print(''.join(ans_q))
else:
    print(''.join(ans_q)[::-1])


Fixed submission:

from collections import deque
s = input()
q = int(input())
s = deque(s)
ans = []
ans_s = ''
one_count = 0
key = 0
for i in range(q):
    ans.append(list(input().split()))
for i in ans:
    if int(i[0])==1:
        one_count += 1
    else:
        if one_count%2==0:
            if int(i[1]) == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if int(i[1]) == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])

if one_count%2==0:
    print(''.join(s))
else:
    print(''.join(s)[::-1])