Buggy python submission (verdict: Runtime Error):
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)
    for i in range(q):
        if int(Q[i][0])==1:
            if i!=q-1 and int(Q[i+1][0])==2 and int(Q[i+1][1])==1:
                d.append(int(Q[i+1][2]))
                d.reverse()
                i=i+1
            else:
                d.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                d.appendleft(Q[i][2])
                #print(s)
            else:
                d.append(Q[i][2])
                #print(s)
    print(''.join(list(d)))






resolve()

Fixed submission:
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    reverse= False
    for i in range(q):
        if int(Q[i][0])==1:
            reverse=not reverse
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                if reverse:
                    d.append(Q[i][2])
                else:
                    d.appendleft(Q[i][2])
                #print(s)
            else:
                if reverse:
                    d.appendleft(Q[i][2])
                else:
                    d.append(Q[i][2])
                #print(s)

    if reverse:
        print(''.join(list(reversed(d))))
    else:
        print(''.join(list(d)))






resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)
    for i in range(q):
        if int(Q[i][0])==1:
            if i!=q-1 and int(Q[i+1][0])==2 and int(Q[i+1][1])==1:
                d.append(int(Q[i+1][2]))
                d.reverse()
                i=i+1
            else:
                d.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                d.appendleft(Q[i][2])
                #print(s)
            else:
                d.append(Q[i][2])
                #print(s)
    print(''.join(list(d)))






resolve()

Fixed submission:
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    reverse= False
    for i in range(q):
        if int(Q[i][0])==1:
            reverse=not reverse
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                if reverse:
                    d.append(Q[i][2])
                else:
                    d.appendleft(Q[i][2])
                #print(s)
            else:
                if reverse:
                    d.appendleft(Q[i][2])
                else:
                    d.append(Q[i][2])
                #print(s)

    if reverse:
        print(''.join(list(reversed(d))))
    else:
        print(''.join(list(d)))






resolve()

Buggy python submission (verdict: Runtime Error):
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)
    rev=0
    for i in range(q):
        if int(Q[i][0])==1:
            if i!=q-1 and int(Q[i+1][0])==2 and int(Q[i+1][1])==1:
                d.append(int(Q[i+1][2]))
                d.reverse()
                i=i+1
            else:
                d.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                d.appendleft(Q[i][2])
                #print(s)
            else:
                d.append(Q[i][2])
                #print(s)
    print(''.join(list(d)))






resolve()

Fixed submission:
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    reverse= False
    for i in range(q):
        if int(Q[i][0])==1:
            reverse=not reverse
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                if reverse:
                    d.append(Q[i][2])
                else:
                    d.appendleft(Q[i][2])
                #print(s)
            else:
                if reverse:
                    d.appendleft(Q[i][2])
                else:
                    d.append(Q[i][2])
                #print(s)

    if reverse:
        print(''.join(list(reversed(d))))
    else:
        print(''.join(list(d)))






resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)

    for i in range(q):
        if int(Q[i][0])==1:
            d.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                d.appendleft(Q[i][2])
                #print(s)
            else:
                d.append(Q[i][2])
                #print(s)
    print(''.join(list(d)))






resolve()

Fixed submission:
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    reverse= False
    for i in range(q):
        if int(Q[i][0])==1:
            reverse=not reverse
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                if reverse:
                    d.append(Q[i][2])
                else:
                    d.appendleft(Q[i][2])
                #print(s)
            else:
                if reverse:
                    d.appendleft(Q[i][2])
                else:
                    d.append(Q[i][2])
                #print(s)

    if reverse:
        print(''.join(list(reversed(d))))
    else:
        print(''.join(list(d)))






resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)

    for i in range(q):
        if int(Q[i][0])==1:
            d.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                d.appendleft(Q[i][2])
                #print(s)
            else:
                d.append(Q[i][2])
                #print(s)
    print(''.join(list(d)))






resolve()

Fixed submission:
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    reverse= False
    for i in range(q):
        if int(Q[i][0])==1:
            reverse=not reverse
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                if reverse:
                    d.append(Q[i][2])
                else:
                    d.appendleft(Q[i][2])
                #print(s)
            else:
                if reverse:
                    d.appendleft(Q[i][2])
                else:
                    d.append(Q[i][2])
                #print(s)

    if reverse:
        print(''.join(list(reversed(d))))
    else:
        print(''.join(list(d)))






resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    s=list(input())
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)

    for i in range(q):
        if int(Q[i][0])==1:
            s.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                s.insert(0,Q[i][2])
                #print(s)
            else:
                s.append(Q[i][2])
                #print(s)
    print(*s,sep='')






resolve()

Fixed submission:
def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    reverse= False
    for i in range(q):
        if int(Q[i][0])==1:
            reverse=not reverse
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                if reverse:
                    d.append(Q[i][2])
                else:
                    d.appendleft(Q[i][2])
                #print(s)
            else:
                if reverse:
                    d.appendleft(Q[i][2])
                else:
                    d.append(Q[i][2])
                #print(s)

    if reverse:
        print(''.join(list(reversed(d))))
    else:
        print(''.join(list(d)))






resolve()