Buggy python submission (verdict: Time Limit Exceeded):
# problem D 
s = input()
Q = int(input())
    
t = True
    
for i in range(Q):
    # input をforの中に組み込む
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s = ''.join([query[2],s])
        else:
            s = ''.join([s,query[2]])
    
if not t:
    s = s[::-1]
        
print(s)

Fixed submission:
from collections import deque

s = deque(input())
Q = int(input())
    
t = True
    
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
            
s = ''.join(s)
    
if not t:
    s = s[::-1]
        
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# problem D 
s = input()
Q = int(input())
    
summ = 0
    
for i in range(Q):
    # input をforの中に組み込む
    query = input().split()
    if query[0] == '1':
        summ += 1
    else:
        if(summ % 2 == 0 and query[1] == '1') or (summ % 2 == 1 and query[1] == '2'):
            s = ''.join([query[2],s])
        else:
            s = ''.join([s,query[2]])
    
if summ % 2 == 1:
    s = s[::-1]
        
print(s)

Fixed submission:
from collections import deque

s = deque(input())
Q = int(input())
    
t = True
    
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
            
s = ''.join(s)
    
if not t:
    s = s[::-1]
        
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# problem D
s = input()
Q = int(input())

query = [input().split() for _ in range(Q)]
    
summ = 0
    
for i in query:
    if int(i[0]) == 1:
        summ += 1
    elif (summ % 2 == 0 and int(i[1]) == 1) or (summ % 2 == 1 and int(i[1]) == 2):
        s = ''.join([str(i[2]),s])
    else:
        s = ''.join([s,str(i[2])])
    
if summ % 2 == 1:
    s = s[::-1]
        
print(s)

Fixed submission:
from collections import deque

s = deque(input())
Q = int(input())
    
t = True
    
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
            
s = ''.join(s)
    
if not t:
    s = s[::-1]
        
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# problem D
s = input()
Q = int(input())

query = []
for i in range(0,Q):
    query.append(input().split())
    
summ = 0
hanten = 0
    
for i in query:
    if int(i[0]) == 1:
        summ += 1
    elif (summ % 2 == 0 and int(i[1]) == 1) or (summ % 2 == 1 and int(i[1]) == 2):
        s = ''.join([str(i[2]),s])
    else:
        s = ''.join([s,str(i[2])])
    
if summ % 2 == 1:
    s = s[::-1]
        
print(s)

Fixed submission:
from collections import deque

s = deque(input())
Q = int(input())
    
t = True
    
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
            
s = ''.join(s)
    
if not t:
    s = s[::-1]
        
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# problem D

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

query = []
for i in range(0,Q):
    query.append(input().split())

s = S
    
for i in query:
    if int(i[0]) == 1:
        # s を反転させる
        s = s[::-1]
    elif int(i[1]) == 1:
        # 先頭に i[2] をくっつける
        s = str(i[2]) + s
    else:
        # しっぽに i[2] をくっつける
        s = s + str(i[2])

print(s)

Fixed submission:
from collections import deque

s = deque(input())
Q = int(input())
    
t = True
    
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
            
s = ''.join(s)
    
if not t:
    s = s[::-1]
        
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
# problem D

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

query = []
for i in range(0,Q):
    query.append(input().split())

s = S
    
for i in query:
    if int(i[0]) == 1:
        # s を反転させる
        s = s[::-1]
    else:
        if int(i[1]) == 1:
            # 先頭に i[2] をくっつける
            s = str(i[2]) + s
        else:
            # しっぽに i[2] をくっつける
            s = s + str(i[2])

print(s)

Fixed submission:
from collections import deque

s = deque(input())
Q = int(input())
    
t = True
    
for i in range(Q):
    query = input().split()
    if query[0] == '1':
        t = not t
    else:
        if(t and query[1] == '1') or (not t and query[1] == '2'):
            s.appendleft(query[2])
        else:
            s.append(query[2])
            
s = ''.join(s)
    
if not t:
    s = s[::-1]
        
print(s)