Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
S = ''
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                s = li.pop() + s
            else:
                s = s + li.pop()
        else:
            if li[1] == '2':
                s = li.pop() + s
            else:
                s = s + li.pop()

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

Fixed submission:
from collections import deque

s = input()
q = int(input())
S = deque(s)
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
        else:
            if li[1] == '2':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
s = ''.join(S)
if not head:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    q = int(input())
    S = ''
    for i in range(q):
        li = input().split()
        if li[0] == '1':
            s = s[::-1]
        else:
            if li[1] == '1':
                s = li.pop() + s
            else:
                s = s + li.pop()
    print(s)
if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

s = input()
q = int(input())
S = deque(s)
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
        else:
            if li[1] == '2':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
s = ''.join(S)
if not head:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = input()
    q = int(input())
    S = ''
    for i in range(q):
        li = input().split()
        if li[0] == '1':
            s = s[::-1]
        else:
            if li[1] == '1':
                s = li.pop() + s
            else:
                s = s + li.pop()
    print(s)
if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

s = input()
q = int(input())
S = deque(s)
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
        else:
            if li[1] == '2':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
s = ''.join(S)
if not head:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    s = list(input())
    q = int(input())
    S = ''
    for i in range(q):
        li = input().split()
        if li[0] == '1':
            s.reverse()
        else:
            if li[1] == '1':
                s = [li[2]]  + s
            else:
                s = s + [li[2]]
    for i in s:
        S += i
    print(S)

if __name__ == '__main__':
    main()

Fixed submission:
from collections import deque

s = input()
q = int(input())
S = deque(s)
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
        else:
            if li[1] == '2':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
s = ''.join(S)
if not head:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
S = ''
for i in range(q):
    li = input().split()
    if li[0] == '1':
        s.reverse()
    else:
        if li[1] == '1':
            s = [li[2]]  + s
        else:
            s = s + [li[2]]
for i in s:
    S += i
print(S)

Fixed submission:
from collections import deque

s = input()
q = int(input())
S = deque(s)
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
        else:
            if li[1] == '2':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
s = ''.join(S)
if not head:
    s = s[::-1]
print(s)