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


Fixed submission:
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')

Buggy python submission (verdict: Runtime Error):
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])
    print(start,owari,r)

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')


Fixed submission:
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')

Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
q=int(input())
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            s.insert(0,data[2])
        else:
            s.append(data[2])
    else:
        if(r==1):
            s.append(data[2])
        else:
            s.insert(0,data[2])

if(r==-1):
    s.reverse()
print(''.join(s))

Fixed submission:
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')

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

Fixed submission:
s=list(input())
q=int(input())
start=[]
owari=[]
r=1
for i in range(q):
    data=input().split()
    if(len(data)==1):
        r*=-1
    elif(data[1]=="1"):
        if(r==1):
            start.append(data[2])
        else:
            owari.append(data[2])
    else:
        if(r==1):
            owari.append(data[2])
        else:
            start.append(data[2])

if(r==1):
    start.reverse()
    print(''.join(start),end='')
    print(''.join(s),end='')
    print(''.join(owari),end='')
else:
    owari.reverse()
    s.reverse()
    print(''.join(owari),end='')
    print(''.join(s),end='')
    print(''.join(start),end='')