Buggy python submission (verdict: Time Limit Exceeded):
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        s.reverse()
    else:
        if t[1] == "1":
            s.appendleft(t[2])
        else:
            s.append(t[2])
            
print("".join(s))

Fixed submission:
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
#flg:反転してるときtrue,してないときFalse
flg = False

for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        if flg:
            flg = False
        else:
            flg = True
    else:
        if t[1] == "1" and flg == False:
            s.appendleft(t[2])
        elif t[1] == "1" and flg == True:
            s.append(t[2])
        elif t[1] == "2" and flg == False:
            s.append(t[2])
        else:
            s.appendleft(t[2])
 
    
if flg:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        s.reverse()
    else:
        if t[1] == "1":
            s.appendleft(t[2])
        else:
            s.append(t[2])
            
print("".join(s))

Fixed submission:
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
#flg:反転してるときtrue,してないときFalse
flg = False

for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        if flg:
            flg = False
        else:
            flg = True
    else:
        if t[1] == "1" and flg == False:
            s.appendleft(t[2])
        elif t[1] == "1" and flg == True:
            s.append(t[2])
        elif t[1] == "2" and flg == False:
            s.append(t[2])
        else:
            s.appendleft(t[2])
 
    
if flg:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
#D
from collections import deque
s = deque(input())
q = int(input())
for _ in range(q):
    t = list(map(str,input().split()))
    if t[0] == '1':
        s.reverse()
    else:
        if t[1] == "1":
            s.appendleft(t[2])
        else:
            s.append(t[2])
            
print("".join(s))

Fixed submission:
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
#flg:反転してるときtrue,してないときFalse
flg = False

for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        if flg:
            flg = False
        else:
            flg = True
    else:
        if t[1] == "1" and flg == False:
            s.appendleft(t[2])
        elif t[1] == "1" and flg == True:
            s.append(t[2])
        elif t[1] == "2" and flg == False:
            s.append(t[2])
        else:
            s.appendleft(t[2])
 
    
if flg:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
#D
s = input()
q = int(input())
query = []
for _ in range(q):
    t = list(map(str,input().split()))
    if t[0] == '1':
        s = s[::-1]
    else:
        if t[1] == "1":
            s = t[2] + s
        else:
            s = s + t[2]
            
print(s)

Fixed submission:
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
#flg:反転してるときtrue,してないときFalse
flg = False

for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        if flg:
            flg = False
        else:
            flg = True
    else:
        if t[1] == "1" and flg == False:
            s.appendleft(t[2])
        elif t[1] == "1" and flg == True:
            s.append(t[2])
        elif t[1] == "2" and flg == False:
            s.append(t[2])
        else:
            s.appendleft(t[2])
 
    
if flg:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
#D
s = input()
q = int(input())
query = []
for _ in range(q):
    t = list(map(str,input().split()))
    if t[0] == '1':
        s = s[::-1]
    else:
        if t[1] == "1":
            s = t[2] + s
        else:
            s = s + t[2]
            
print(s)

Fixed submission:
#D
#import sys
#input = sys.stdin.readline
from collections import deque
s = deque(input())
q = int(input())
#flg:反転してるときtrue,してないときFalse
flg = False

for _ in range(q):
    t = tuple(map(str,input().split()))
    if t[0] == '1':
        if flg:
            flg = False
        else:
            flg = True
    else:
        if t[1] == "1" and flg == False:
            s.appendleft(t[2])
        elif t[1] == "1" and flg == True:
            s.append(t[2])
        elif t[1] == "2" and flg == False:
            s.append(t[2])
        else:
            s.appendleft(t[2])
 
    
if flg:
    s.reverse()
print("".join(s))