Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
queri=[]
rv=0

if rv==1: s=s[::-1]
forward=""
back=""
for i in range(q):
    queri=list(map(lambda x:x,input().split()))
    if queri[0]=="2":
        rvt=(rv+int(queri[1]))%2
        if rvt==1: forward+=queri[2]
        else: back+=queri[2]

    else: rv=(rv+1)%2

ans=forward[::-1]+s+back
print(ans if rv==0 else ans[::-1])


Fixed submission:
s=input()
q=int(input())
queri=[]
rv=0
forward=[]
back=[]
for i in range(q):
    queri=list(map(lambda x:x,input().split()))
    if queri[0]=="2":
        rvt=(rv+int(queri[1]))%2
        if rvt==1: forward.append(queri[2])
        else: back.append(queri[2])

    else: rv=(rv+1)%2

if rv==0:
    for i in range(len(forward)-1,-1,-1):
        print(forward[i],end="")
    print(s,end="")
    for i in range(len(back)):
        print(back[i],end="")
        
if rv==1:
    for i in range(len(back)-1,-1,-1):
        print(back[i],end="")
    print(s[::-1],end="")
    for i in range(len(forward)):
        print(forward[i],end="")

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
queri=[]
rv=0

for i in range(q):
    tmp=list(map(lambda x: x,input().split()))
    queri.append(tmp)
    if tmp[0]=="1": rv+=1
rv=rv%2

if rv==1: s=s[::-1]
forward=""
back=""
for i in range(q):
    if queri[i][0]=="2":
        rvt=(rv+int(queri[i][1]))%2
        if rvt==1: forward+=queri[i][2]
        else: back+=queri[i][2]

    else: rv=(rv+1)%2

print(forward[::-1],end="")
print(s,end="")
print(back)

Fixed submission:
s=input()
q=int(input())
queri=[]
rv=0
forward=[]
back=[]
for i in range(q):
    queri=list(map(lambda x:x,input().split()))
    if queri[0]=="2":
        rvt=(rv+int(queri[1]))%2
        if rvt==1: forward.append(queri[2])
        else: back.append(queri[2])

    else: rv=(rv+1)%2

if rv==0:
    for i in range(len(forward)-1,-1,-1):
        print(forward[i],end="")
    print(s,end="")
    for i in range(len(back)):
        print(back[i],end="")
        
if rv==1:
    for i in range(len(back)-1,-1,-1):
        print(back[i],end="")
    print(s[::-1],end="")
    for i in range(len(forward)):
        print(forward[i],end="")

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
queri=[]
rv=0

for i in range(q):
    tmp=list(map(lambda x: x,input().split()))
    queri.append(tmp)
    if tmp[0]=="1": rv+=1
rv=rv%2

if rv==1: s=s[::-1]
ans=[s]

for i in range(q):
    if queri[i][0]=="2":
        rvt=(rv+int(queri[i][1]))%2
        if rvt==1: ans=[queri[i][2]]+ans
        else: s=ans.append(queri[i][2])

    else: rv=(rv+1)%2

for i in range(len(ans)):
    print(ans[i],end="")

Fixed submission:
s=input()
q=int(input())
queri=[]
rv=0
forward=[]
back=[]
for i in range(q):
    queri=list(map(lambda x:x,input().split()))
    if queri[0]=="2":
        rvt=(rv+int(queri[1]))%2
        if rvt==1: forward.append(queri[2])
        else: back.append(queri[2])

    else: rv=(rv+1)%2

if rv==0:
    for i in range(len(forward)-1,-1,-1):
        print(forward[i],end="")
    print(s,end="")
    for i in range(len(back)):
        print(back[i],end="")
        
if rv==1:
    for i in range(len(back)-1,-1,-1):
        print(back[i],end="")
    print(s[::-1],end="")
    for i in range(len(forward)):
        print(forward[i],end="")

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
queri=[]
rv=0

for i in range(q):
    tmp=list(map(lambda x: x,input().split()))
    queri.append(tmp)
    if tmp[0]=="1": rv+=1
rv=rv%2

if rv==1: s=s[::-1]
ans=[s]

for i in range(q):
    if queri[i][0]=="2":
        rvt=(rv+int(queri[i][1]))%2
        if rvt==1: ans=[queri[i][2]]+ans
        else: s=ans.append(queri[i][2])

    else: rv=(rv+1)%2

for i in range(len(ans)):
    print(ans[i],end="")

Fixed submission:
s=input()
q=int(input())
queri=[]
rv=0
forward=[]
back=[]
for i in range(q):
    queri=list(map(lambda x:x,input().split()))
    if queri[0]=="2":
        rvt=(rv+int(queri[1]))%2
        if rvt==1: forward.append(queri[2])
        else: back.append(queri[2])

    else: rv=(rv+1)%2

if rv==0:
    for i in range(len(forward)-1,-1,-1):
        print(forward[i],end="")
    print(s,end="")
    for i in range(len(back)):
        print(back[i],end="")
        
if rv==1:
    for i in range(len(back)-1,-1,-1):
        print(back[i],end="")
    print(s[::-1],end="")
    for i in range(len(forward)):
        print(forward[i],end="")

Buggy python submission (verdict: Time Limit Exceeded):
def f(t):
    return t

s=input()
q=int(input())
queri=[]
rv=0

for i in range(q):
    tmp=list(map(f,input().split()))
    queri.append(tmp)
    if tmp[0]=="1": rv+=1
rv=rv%2

if rv==1: s=s[::-1]
ans=[s]

for i in range(q):
    if queri[i][0]=="2":
        rvt=(rv+int(queri[i][1]))%2
        if rvt==1: ans=[queri[i][2]]+ans
        else: s=ans.append(queri[i][2])

    else: rv=(rv+1)%2

for i in range(len(ans)):
    print(ans[i],end="")

Fixed submission:
s=input()
q=int(input())
queri=[]
rv=0
forward=[]
back=[]
for i in range(q):
    queri=list(map(lambda x:x,input().split()))
    if queri[0]=="2":
        rvt=(rv+int(queri[1]))%2
        if rvt==1: forward.append(queri[2])
        else: back.append(queri[2])

    else: rv=(rv+1)%2

if rv==0:
    for i in range(len(forward)-1,-1,-1):
        print(forward[i],end="")
    print(s,end="")
    for i in range(len(back)):
        print(back[i],end="")
        
if rv==1:
    for i in range(len(back)-1,-1,-1):
        print(back[i],end="")
    print(s[::-1],end="")
    for i in range(len(forward)):
        print(forward[i],end="")

Buggy python submission (verdict: Time Limit Exceeded):
def f(t):
    return t

s=input()
q=int(input())
queri=[]
rv=0
for i in range(q):
    tmp=list(map(f,input().split()))
    queri.append(tmp)
    if tmp==["1"]:
        rv+=1
rv=rv%2
if rv==1: s=s[::-1]

for i in range(q):
    if queri[i][0]=="2":
        rvt=(rv+int(queri[i][1]))%2
        if rvt==1: s=queri[i][2]+s
        else: s=s+queri[i][2]

    else: rv=(rv+1)%2

print(s)

Fixed submission:
s=input()
q=int(input())
queri=[]
rv=0
forward=[]
back=[]
for i in range(q):
    queri=list(map(lambda x:x,input().split()))
    if queri[0]=="2":
        rvt=(rv+int(queri[1]))%2
        if rvt==1: forward.append(queri[2])
        else: back.append(queri[2])

    else: rv=(rv+1)%2

if rv==0:
    for i in range(len(forward)-1,-1,-1):
        print(forward[i],end="")
    print(s,end="")
    for i in range(len(back)):
        print(back[i],end="")
        
if rv==1:
    for i in range(len(back)-1,-1,-1):
        print(back[i],end="")
    print(s[::-1],end="")
    for i in range(len(forward)):
        print(forward[i],end="")