Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)

for t in ls:
    if t[0] == '1':
        ans.reverse()
    elif t[0] == '2':
        if t[1] == '1':
            ans.appendleft(t[2])
        elif t[1] == '2':
            ans.append(t[2])

print("".join(ans))

Fixed submission:
from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)
cnt = 0

for t in ls:
    if t[0] == '1':
        cnt += 1
    elif t[0] == '2':
        if cnt % 2 == 0:
            if t[1] == '1':
                ans.appendleft(t[2])
            elif t[1] == '2':
                ans.append(t[2])
        elif cnt % 2 == 1:
            if t[1] == '1':
                ans.append(t[2])
            elif t[1] == '2':
                ans.appendleft(t[2])

if cnt % 2 == 0:
    print("".join(ans))
elif cnt % 2 == 1:
    ans.reverse()
    print("".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)

for t in ls:
    if t[0] == '1':
        ans.reverse()
    elif t[0] == '2':
        if t[1] == '1':
            ans.appendleft(t[2])
        elif t[1] == '2':
            ans.append(t[2])

print("".join(ans))

Fixed submission:
from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)
cnt = 0

for t in ls:
    if t[0] == '1':
        cnt += 1
    elif t[0] == '2':
        if cnt % 2 == 0:
            if t[1] == '1':
                ans.appendleft(t[2])
            elif t[1] == '2':
                ans.append(t[2])
        elif cnt % 2 == 1:
            if t[1] == '1':
                ans.append(t[2])
            elif t[1] == '2':
                ans.appendleft(t[2])

if cnt % 2 == 0:
    print("".join(ans))
elif cnt % 2 == 1:
    ans.reverse()
    print("".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)

for t in ls:
    if t[0] == '1':
        ans.reverse()
    elif t[0] == '2':
        if t[1] == '1':
            ans.appendleft(t[2])
        elif t[1] == '2':
            ans.append(t[2])

l = list(ans)

print("".join(ans))

Fixed submission:
from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)
cnt = 0

for t in ls:
    if t[0] == '1':
        cnt += 1
    elif t[0] == '2':
        if cnt % 2 == 0:
            if t[1] == '1':
                ans.appendleft(t[2])
            elif t[1] == '2':
                ans.append(t[2])
        elif cnt % 2 == 1:
            if t[1] == '1':
                ans.append(t[2])
            elif t[1] == '2':
                ans.appendleft(t[2])

if cnt % 2 == 0:
    print("".join(ans))
elif cnt % 2 == 1:
    ans.reverse()
    print("".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

for t in ls:
    if t[0] == '1':
        s = s[::-1]
    elif t[0] == '2':
        if t[1] == '1':
            s = t[2] + s
        elif t[1] == '2':
            s = s + t[2]
    
print(s)

Fixed submission:
from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)
cnt = 0

for t in ls:
    if t[0] == '1':
        cnt += 1
    elif t[0] == '2':
        if cnt % 2 == 0:
            if t[1] == '1':
                ans.appendleft(t[2])
            elif t[1] == '2':
                ans.append(t[2])
        elif cnt % 2 == 1:
            if t[1] == '1':
                ans.append(t[2])
            elif t[1] == '2':
                ans.appendleft(t[2])

if cnt % 2 == 0:
    print("".join(ans))
elif cnt % 2 == 1:
    ans.reverse()
    print("".join(ans))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

for i in range(q):
    if ls[i][0] == '1':
        s = s[::-1]
    elif ls[i][0] == '2':
        if ls[i][1] == '1':
            s = ls[i][2] + s
        elif ls[i][1] == '2':
            s = s + ls[i][2]
    
print(s)

Fixed submission:
from collections import deque

s = input()
q = int(input())
ls = [input().split() for _ in range(q)]

ans = deque(s)
cnt = 0

for t in ls:
    if t[0] == '1':
        cnt += 1
    elif t[0] == '2':
        if cnt % 2 == 0:
            if t[1] == '1':
                ans.appendleft(t[2])
            elif t[1] == '2':
                ans.append(t[2])
        elif cnt % 2 == 1:
            if t[1] == '1':
                ans.append(t[2])
            elif t[1] == '2':
                ans.appendleft(t[2])

if cnt % 2 == 0:
    print("".join(ans))
elif cnt % 2 == 1:
    ans.reverse()
    print("".join(ans))