Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

s = input()
head = 1 #1:forward, -1: reverse

q = int(input())
sl = [ s[i] for i in range(len(s)) ]

for i in range(q):
    ql = input()
    if ql[0] == '1':
        head *= -1
    elif ql[0] == '2':
        (op, f, c) = ql.split()
        ht = 1
        if f == '1':
            ht = head
        else:
            #f == '2':
            ht = head * -1

        if ht == 1:
            sl.insert(0, c)
        else:
            sl.append(c)


if head == 1:
    print(''.join(sl))
else:
    print(''.join(reversed(sl)))


Fixed submission:
#!/usr/bin/python3
from collections import deque

s = input()
head = 1 #1:forward, -1: reverse

q = int(input())
sl = [ s[i] for i in range(len(s)) ]
sq = deque(sl)


for i in range(q):
    ql = input()
    if ql[0] == '1':
        head *= -1
    elif ql[0] == '2':
        (op, f, c) = ql.split()
        ht = 1
        if f == '1':
            ht = head
        else:
            #f == '2':
            ht = head * -1

        if ht == 1:
            sq.appendleft(c)
        else:
            sq.append(c)


if head == 1:
    print(''.join(sq))
else:
    print(''.join(reversed(sq)))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

s = input()
head = 1 #1:forward, -1: reverse

q = int(input())
sl = [ s[i] for i in range(len(s)) ]

for i in range(q):
    ql = input()
    if ql[0] == '1':
        head *= -1
    elif ql[0] == '2':
        (op, f, c) = ql.split()
        ht = 1
        if f == '1':
            ht = head
        else:
            #f == '2':
            ht = head * -1

        if ht == 1:
            sl.insert(0, c)
        else:
            sl.append(c)


if head == 1:
    print(''.join(sl))
else:
    print(''.join(reversed(sl)))


Fixed submission:
#!/usr/bin/python3
from collections import deque

s = input()
head = 1 #1:forward, -1: reverse

q = int(input())
sl = [ s[i] for i in range(len(s)) ]
sq = deque(sl)


for i in range(q):
    ql = input()
    if ql[0] == '1':
        head *= -1
    elif ql[0] == '2':
        (op, f, c) = ql.split()
        ht = 1
        if f == '1':
            ht = head
        else:
            #f == '2':
            ht = head * -1

        if ht == 1:
            sq.appendleft(c)
        else:
            sq.append(c)


if head == 1:
    print(''.join(sq))
else:
    print(''.join(reversed(sq)))

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python3

s = input()
head = 1 #1:forward, -1: reverse

q = int(input())

for i in range(q):
    ql = input()
    if ql[0] == '1':
        head *= -1
    elif ql[0] == '2':
        (op, f, c) = ql.split()
        ht = 1
        if f == '1':
            ht = head
        else:
            #f == '2':
            ht = head * -1

        if ht == 1:
            s = c + s
        else:
            s = s + c


if head == 1:
    print(s)
else:
    print(s[::-1])


Fixed submission:
#!/usr/bin/python3
from collections import deque

s = input()
head = 1 #1:forward, -1: reverse

q = int(input())
sl = [ s[i] for i in range(len(s)) ]
sq = deque(sl)


for i in range(q):
    ql = input()
    if ql[0] == '1':
        head *= -1
    elif ql[0] == '2':
        (op, f, c) = ql.split()
        ht = 1
        if f == '1':
            ht = head
        else:
            #f == '2':
            ht = head * -1

        if ht == 1:
            sq.appendleft(c)
        else:
            sq.append(c)


if head == 1:
    print(''.join(sq))
else:
    print(''.join(reversed(sq)))