Buggy python submission (verdict: Runtime Error):
s=[input()]
q=int(input())
turn=True

for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            s.appendleft(qq[2])
        else:
            s.append(qq[2])

text="".join(s)
print(text if turn else text[::-1])

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Buggy python submission (verdict: Runtime Error):
s=[input()]
q=int(input())
turn=True
for i in ragne(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==not (int(qq[1])-1]):
            s.insert(0,qq[2])
        else:
            s.append(qq[2])
text="".join(s)
print(text if turn else text[::-1])

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=[input()]
q=int(input())
turn=True
dic={'1':True,'2':False}

for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==dic[qq[1]]:
            s.insert(0,qq[2])
        else:
            s.append(qq[2])
text="".join(s)
print(text if turn else text[::-1])

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Buggy python submission (verdict: Runtime Error):
ad=[[],[]]
add=[[],[]]
count=0
s=input()
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        count+=1
        ad[0].reverse()
        ad[1].reverse()
        add=[add[0]+=ad[1],add[1]+=ad[0]]
        ad=[[],[]]
    elif t[1]=='1':
        ad[0].insert(0,t[2])
    else:
        ad[1].append(t[2])


if count%2==0:
    print(''.join(add[0]+ad[0])+s+''.join(add[1]+ad[1]))
else:
    print(''.join(add[0]+ad[0])+s[::-1]+''.join(add[1]+ad[1]))

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
ad=[[],[]]
count=0
s=input()
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        count+=1
        ad[0].reverse()
        ad[1].reverse()
        ad=[ad[1],ad[0]]
    elif t[1]=='1':
        ad[0].insert(0,t[2])
    else:
        ad[1].append(t[2])

if count%2==0:
    print(''.join(ad[0])+s+''.join(ad[1]))
else:
    print(''.join(ad[0])+s[::-1]+''.join(ad[1]))

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Buggy python submission (verdict: Runtime Error):
ad=[[],[]]
count=0
s=input()
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        count+=1
        ad[1].reverse()
        ad[0].reverse()
        ad=[ad[1],ad[0]]
    elif t[1]=='1':
        ad[0].insert(0,t[2])
    else:
        ad[1].append(t[2])

if count%2==0:
    print(''.join(ad[0],s,ad[1]))
else:
    print(''.join(ad[0]),end='')
    for i in range(len(s)):
        print(s[-(i+1)],end='')
    print(''.join(ad[1]))

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
#D
s=[i for i in input()]
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        s.reverse()
    elif t[1]=='1':
        s.insert(0,t[2])
    else:
        s.append(t[2])
        
print(''.join(s))

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
#D
S=input()
s=[]
for i in range(len(S)):
    s.append(S[i])
q=int(input())
for i in range(q):
    t=input().split()
    if t[0]=='1':
        s.reverse()
    elif t[1]=='1':
        s.insert(0,t[2])
    else:
        s.append(t[2])
        
print(''.join(s))

Fixed submission:
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])