Buggy python submission (verdict: Time Limit Exceeded):
def sf(s,queries):

    is_reversed = 0

    for query in queries:
        addl = []
        addr = []
        if query[0] == '1':
            is_reversed ^= 1
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if is_reversed == 0 and f == '1' or is_reversed == 1 and f == '2':
                addl = [c]
            elif is_reversed == 0 and f == '2' or is_reversed == 1 and f == '1':
                addr = [c]

            s = addl + s + addr

    return ''.join(s) if not is_reversed else ''.join(reversed(s))


if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(sf(s,ql))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
def sf(s,queries):

    is_reversed = 0

    for query in queries:
        addl = []
        addr = []
        if query[0] == '1':
            is_reversed ^= 1
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if is_reversed == 0 and f == '1' or is_reversed == 1 and f == '2':
                addl.append(c)
            elif is_reversed == 0 and f == '2' or is_reversed == 1 and f == '1':
                addr.append(c)

            s = addl + s + addr

    return ''.join(s) if not is_reversed else ''.join(reversed(s))


if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(sf(s,ql))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
def add(s,f,c,is_reversed):
    if f == '1':
        ht = 0
    elif f == '2':
        ht = 1
        
    if is_reversed != ht:
            ns = s + c 
    if is_reversed == ht:
            ns = c + s

    return ns

def msf(s,q,ql):
    len_ql = len(ql)
    is_reversed = 0
    for i in range(0,len_ql):
        t1 = ql[i][0]
        if t1 == "1":
            is_reversed ^= 1
        elif t1 == "2":
            f = ql[i][1]
            c = list(ql[i][2])
            s = add(s,f,c,is_reversed)

    return ''.join(s) if not is_reversed else ''.join(reversed(s))
    
if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [list(input().split()) for _ in range(q)]
    
    print(msf(s,q,ql))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
def msf(s,q,ql):
    len_ql = len(ql)
    for i in range(1,len_ql-1):
        t1 = ql[i][0]
        if t1 == "1":
            s = list(reversed(s))
        elif t1 == "2":
            f = ql[i][1]
            c = list(ql[i][2])
            if f == "1":
                s = c + s
            elif f == "2":
                s = s + c
    return s
    
if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [list(input().split()) for _ in range(q)]

    ql = [['0']] + ql + [['0']]
    len_ql = len(ql)

    for i in range(1,len_ql-1):
        if len_ql <= i:
            break
        elif ql[i][0] == "1" and ql[i-1][0] == "1" :
            ql = ql[0:i-1] + ql[i+1:]
            len_ql -= 2
        else:
            pass

    print(''.join(msf(s,q,ql)))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
def msf(s,q,ql):
    len_ql = len(ql)
    for i in range(1,len_ql-1):
        t1 = ql[i][0]
        if t1 == "1":
            s = list(reversed(s))
        elif t1 == "2":
            f = ql[i][1]
            c = list(ql[i][2])
            if f == "1":
                s = c + s
            elif f == "2":
                s = s + c
    return s
    
if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [list(input().split()) for _ in range(q)]

    ql = [['0']] + ql + [['0']]
    len_ql = len(ql)

    for i in range(1,len_ql-1):
        if len_ql <= i:
            break
        elif ql[i][0] == "1" and ql[i-1][0] == "1" :
            ql = ql[0:i-1] + ql[i+1:]
            len_ql -= 2
        else:
            pass

    print(''.join(msf(s,q,ql)))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    s = list(input())
    q = int(input())
    #ql = [list(input().split()) for _ in range(q)]

    for _ in range(q):
        ql = list(input().split())
        t = ql[0]
        #print(br)
        if t == "1":
            s = list(reversed(s))
            #print(s)
        elif t == "2":
            f = ql[1]
            c = list(ql[2])
            if f == "1":
                s = c + s
            elif f == "2":
                s = s + c
            
    print(''.join(s))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
def string_formation(s,q,ql):
    len_ql = len(ql)
    for i in range(len_ql):
        t = ql[i][0]
        #print(br)
        if t == "1":
            s = list(reversed(s))
            #print(s)
        elif t == "2":
            f = ql[i][1]
            c = list(ql[i][2])
            if f == "1":
                s = c + s
            elif f == "2":
                s = s + c
    return s

if __name__ == '__main__':
    s = input()
    q = int(input())
    ql = [list(input().split()) for _ in range(q)]

    ans = string_formation(list(s),q,ql)
    print(''.join(ans))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
def string_formation(s,q,ql):
    len_ql = len(ql)
    for i in range(len_ql):
        t = ql[i][0]
        #print(br)
        if t == "1":
            s = list(reversed(s))
            #print(s)
        elif t == "2":
            f = ql[i][1]
            c = list(ql[i][2])
            if f == "1":
                s = c + s
            elif f == "2":
                s = s + c
    return s

if __name__ == '__main__':
    s = input()
    q = int(input())
    ql = [list(input().split()) for _ in range(q)]

    ans = string_formation(list(s),q,ql)
    print(''.join(ans))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))

Buggy python submission (verdict: Time Limit Exceeded):
def flip(s):
    return list(reversed(s))

def add(s,ql):
    if ql[1] == "1":
        return list(ql[2])+s
    elif ql[1] == "2":
        return s+list(ql[2])
        
def string_formation(s,q,ql):
    for i in range(len(ql)):
        br = ql[i][0]
        #print(br)
        if br == "1":
            s = flip(s)
            #print(s)
        elif br == "2":
            s = add(s,ql[i])
            #print(s)
    return s

if __name__ == '__main__':
    s = input()
    q = int(input())
    ql = [list(input().split()) for _ in range(q)]

    #print(s)
    #print(q)
    #print(ql)
    
    ans = string_formation(list(s),q,ql)
    print(''.join(ans))


Fixed submission:
from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))