Buggy python submission (verdict: Runtime Error):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.appendleft(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=front_str+t_str+end_str
ans=list(ans)

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



Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

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

Buggy python submission (verdict: Runtime Error):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''
t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)
for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.appendleft(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=front_str+t_str+end_str
ans=list(ans)

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



Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

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

Buggy python submission (verdict: Runtime Error):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''
t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)
for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.appendleft(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=front_str+t_str+end_str
ans=list(ans)

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



Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

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

Buggy python submission (verdict: Time Limit Exceeded):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))
# print(l)
t_str=deque(s)
gyaku_fig=False
for ll in l:
    if ll[0]=='1':
        t_str=list(t_str)
        t_str=t_str[::-1]
        t_str=deque(t_str)
    elif ll[0]=='2':
            if ll[1]=='1':
                t_str.appendleft(ll[2])
                # t_str=list(ll[2])+t_str
            elif ll[1]=='2':
                t_str.append(ll[2])
                # t_str+=list(ll[2])

t_str=list(t_str)
ans=''.join(t_str)
print(ans)

# t_str=s
# gyaku_fig=False
# for ll in l:
#     if ll[0]=='1':
#         if gyaku_fig==False:
#             gyaku_fig=True
#         elif gyaku_fig==True:
#             gyaku_fig=False
#     elif ll[0]=='2':
#         if gyaku_fig==True:
#             if ll[1]=='1':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='2':
#                 t_str+=ll[2]
#         elif gyaku_fig==False:
#             if ll[1]=='2':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='1':
#                 t_str+=ll[2]        
# if gyaku_fig==True:
#     print(t_str)
# else:
#     print(t_str[::-1])


Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

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

Buggy python submission (verdict: Time Limit Exceeded):
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))
# print(l)
t_str=deque(s)
gyaku_fig=False
for ll in l:
    if ll[0]=='1':
        t_str=list(t_str)
        t_str=t_str[::-1]
        t_str=deque(t_str)
    elif ll[0]=='2':
            if ll[1]=='1':
                t_str.appendleft(ll[2])
                # t_str=list(ll[2])+t_str
            elif ll[1]=='2':
                t_str.append(ll[2])
                # t_str+=list(ll[2])

t_str=list(t_str)
ans=''.join(t_str)
print(ans)

# t_str=s
# gyaku_fig=False
# for ll in l:
#     if ll[0]=='1':
#         if gyaku_fig==False:
#             gyaku_fig=True
#         elif gyaku_fig==True:
#             gyaku_fig=False
#     elif ll[0]=='2':
#         if gyaku_fig==True:
#             if ll[1]=='1':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='2':
#                 t_str+=ll[2]
#         elif gyaku_fig==False:
#             if ll[1]=='2':
#                 t_str=ll[2]+t_str
#             elif ll[1]=='1':
#                 t_str+=ll[2]        
# if gyaku_fig==True:
#     print(t_str)
# else:
#     print(t_str[::-1])


Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

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

Buggy python submission (verdict: Time Limit Exceeded):
# ABC158 D
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))
# print(l)
t_str=s
for ll in l:
    if ll[0]=='1':
        t_str=t_str[::-1]
    elif ll[0]=='2':
        if ll[1]=='1':
            t_str=ll[2]+t_str
        elif ll[1]=='2':
            t_str+=ll[2]
print(t_str)


Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

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

Buggy python submission (verdict: Time Limit Exceeded):
# ABC158 D
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))
# print(l)
t_str=s
for ll in l:
    if ll[0]=='1':
        t_str=t_str[::-1]
    elif ll[0]=='2':
        if ll[1]=='1':
            t_str=ll[2]+t_str
        elif ll[1]=='2':
            t_str+=ll[2]
print(t_str)


Fixed submission:
# ABC158 D
from collections import deque
s=input()
q=int(input())
l=[]

for i in range(q):
    l.append(list(map(str,input().split())))

cnt=0
front_str=''
end_str=''

t_str=deque(s)
front_str=deque(front_str)
end_str=deque(end_str)

for ll in l:
    if ll[0]=='1':
        cnt+=1
    elif ll[0]=='2':
        if cnt%2==0:
            if ll[1]=='1':
                front_str.appendleft(ll[2])
            elif ll[1]=='2':
                end_str.append(ll[2])
        elif cnt%2==1:
            if ll[1]=='1':
                end_str.append(ll[2])
            elif ll[1]=='2':
                front_str.appendleft(ll[2])
ans=list(front_str)+list(t_str)+list(end_str)

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