Buggy python submission (verdict: Time Limit Exceeded):
S=str(input())
Q=int(input())
which=0
front=[]
back=[]
for i in range(Q):
    a=list(map(str,input().split()))
    if a==["1"]:
        which+=1
        which%=2
        continue
    else:
        if which==0:
            if a[1]=="1":
                front.insert(0,a[2])
            if a[1]=="2":
                back.append(a[2])
        if which==1:
            if a[1]=="1":
                back.append(a[2])
            if a[1]=="2":
                front.insert(0,a[2])
F="".join(front)
B="".join(back)
S=F+S+B
if which==1:
    print("".join(S[len(S)-i-1] for i in range(len(S))))
if which==0:
    print(S)


Fixed submission:
S=str(input())
Q=int(input())
which=0
front=""
back=""
for i in range(Q):
    a=list(map(str,input().split()))
    if a==["1"]:
        which+=1
        which%=2
        continue
    else:
        if which==0:
            if a[1]=="1":
                front=a[2]+front
            if a[1]=="2":
                back+=a[2]
        if which==1:
            if a[1]=="1":
                back+=a[2]
            if a[1]=="2":
                front=a[2]+front

S=front+S+back
if which==1:
    print(S[::-1])
if which==0:
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=str(input())
Q=int(input())
which=0#0 normal #1 reverse
check=[list(map(str,input().split())) for i in range(Q)]
front=[]
back=[]
#print(check)
for i in range(Q):
    if check[i][0]=="1":
        which+=1
        which%=2
        continue
    if check[i][0]!="1":
        if which==0:
            if check[i][1]=="1":
                front.insert(0,check[i][2])
            if check[i][1]=="2":
                back.append(check[i][2])
        if which==1:
            if check[i][1]=="1":
                back.append(check[i][2])
            if check[i][1]=="2":
                front.insert(0,check[i][2])
F="".join(front)
B="".join(back)
S=F+S+B
if which==1:
    print("".join(S[len(S)-i-1] for i in range(len(S))))
if which==0:
    print(S)


Fixed submission:
S=str(input())
Q=int(input())
which=0
front=""
back=""
for i in range(Q):
    a=list(map(str,input().split()))
    if a==["1"]:
        which+=1
        which%=2
        continue
    else:
        if which==0:
            if a[1]=="1":
                front=a[2]+front
            if a[1]=="2":
                back+=a[2]
        if which==1:
            if a[1]=="1":
                back+=a[2]
            if a[1]=="2":
                front=a[2]+front

S=front+S+back
if which==1:
    print(S[::-1])
if which==0:
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
Q=int(input())
which=0#0 normal #1 reverse
check=[list(map(str,input().split())) for i in range(Q)]
#print(check)
for i in range(Q):
    if check[i][0]=="1":
        which+=1
        which%=2
        continue
    if check[i][0]!="1":
        if which==0:
            if check[i][1]=="1":
                S.insert(0,check[i][2])
            if check[i][1]=="2":
                S.append(check[i][2])
        if which==1:
            if check[i][1]=="1":
                S.append(check[i][2])
            if check[i][1]=="2":
                S.insert(0,check[i][2])
if which==1:
    print("".join(S[len(S)-i-1] for i in range(len(S))))
if which==0:
    print("".join(S))


Fixed submission:
S=str(input())
Q=int(input())
which=0
front=""
back=""
for i in range(Q):
    a=list(map(str,input().split()))
    if a==["1"]:
        which+=1
        which%=2
        continue
    else:
        if which==0:
            if a[1]=="1":
                front=a[2]+front
            if a[1]=="2":
                back+=a[2]
        if which==1:
            if a[1]=="1":
                back+=a[2]
            if a[1]=="2":
                front=a[2]+front

S=front+S+back
if which==1:
    print(S[::-1])
if which==0:
    print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
Q=int(input())
which=0#0 normal #1 reverse
check=[list(map(str,input().split())) for i in range(Q)]
#print(check)
for i in range(Q):
    if check[i][0]=="1":
        which+=1
        which%=2
        continue
    if check[i][0]!="1":
        if which==0:
            if check[i][1]=="1":
                S.insert(0,check[i][2])
            if check[i][1]=="2":
                S.append(check[i][2])
        if which==1:
            if check[i][1]=="1":
                S.append(check[i][2])
            if check[i][1]=="2":
                S.insert(0,check[i][2])
if which==1:
    S=S[::-1]
print("".join(S))

Fixed submission:
S=str(input())
Q=int(input())
which=0
front=""
back=""
for i in range(Q):
    a=list(map(str,input().split()))
    if a==["1"]:
        which+=1
        which%=2
        continue
    else:
        if which==0:
            if a[1]=="1":
                front=a[2]+front
            if a[1]=="2":
                back+=a[2]
        if which==1:
            if a[1]=="1":
                back+=a[2]
            if a[1]=="2":
                front=a[2]+front

S=front+S+back
if which==1:
    print(S[::-1])
if which==0:
    print(S)