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

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s=list(input())
q=int(input())

re=False
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s=[q_i[2]]+s
        elif q_i[1]=="2" and re==True:
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s=list(input())
q=int(input())

re=0
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re+=1
    else:
        if q_i[1]=="1" and re%2==0:
            s=[q_i[2]]+s
        elif q_i[1]=="2" and re%2==1:
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re%2==1:
    s=s[::-1]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s=list(input())
q=int(input())

re=0
for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        re+=1
    else:
        if (q_i[1]=="1" and re%2==0) or (q_i[1]=="2" and re%2==1):
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

if re%2==1:
    s=s[::-1]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=sys.stdin.readline().rstrip().split()
    if q_i[0]=="1":
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Runtime Error):
import sys

s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=stdin.readline().rstrip().split()
    if q_i[0]=="1":
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=[q_i[2]]+s
        else:
            s=s+[q_i[2]]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s.append(q_i[2])

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Runtime Error):
s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s=s.append(q_i[2])

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())

re=0
for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        re+=1    
    else:
        if (q_i[1]=="1" and re%2==0) or (q_i[1]=="2" and re%2==1):
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

if re%2==1:
    s=s[::-1]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())

re=0
for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        re+=1    
    else:
        if (q_i[1]=="1" and re%2==0) or (q_i[1]=="2" and re%2==1):
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

if re%2==1:
    s=s[::-1]

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=stdin.readline().rstrip().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

s="".join(s)
print(s)

Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())

for i in range(1,q+1):
    q_i=input().split()
    if q_i==["1"]:
        s=s[::-1]
    else:
        if q_i[1]=="1":
            s=list(q_i[2])+s
        else:
            s=s+list(q_i[2])

s="".join(s)
print(s)
    



Fixed submission:
from collections import deque

s=list(input())
s=deque(s)
q=int(input())

re=False
for i in range(1,q+1):
    q_i=input().split()
    if q_i[0]=="1":
        re= not re
    else:
        if q_i[1]=="1" and re==False:
            s.appendleft(q_i[2])
        elif q_i[1]=="2" and re==True:
            s.appendleft(q_i[2])
        else:
            s.append(q_i[2])

s=list(s)

if re==True:
    s=s[::-1]

s="".join(s)
print(s)