Buggy python submission (verdict: Runtime Error):
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

#s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if inv % 2 ==0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])


Fixed submission:
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if inv % 2 ==0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])

Buggy python submission (verdict: Runtime Error):
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

#s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])


Fixed submission:
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if inv % 2 ==0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
r = []
#先頭の数
t = []
#2つめ
u = []
#3つめ
v = []
for i in range(q):
    a = input()
    r.append(a)
    t.append(int(r[i][0]))
    if r[i][0] == '1':
        u.append('0')
        v.append('0')
    else:
        u.append(r[i][2])
        v.append(r[i][4])
#
if t.count(1) %2 == 1:
    s = ''.join(list(reversed(s)))


for i,j in enumerate(t):
    if j == 2:
        w = (t[i:]).count(1)
        if w % 2 == 1:
            if u[i] == '1':
                u[i] = '2'
            else:
                u[i] = '1'
        if u[i] == '1':
            s = v[i] + s
        else:
            s = s + v[i]
print(s)




Fixed submission:
from collections import deque

s = input()
q = int(input())
query = [input() for _ in range(q)]

s = deque(s)

inv = 0
for q in query :
    if q[0] == '1':
        inv += 1
    else:
        _,f,c = q.split()
        if f == '1':
            if inv % 2 == 0:
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if inv % 2 ==0:
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(s)
print(s if inv % 2 == 0 else s[::-1])