Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = list(input().split() for i in range(Q))
ans = S
sentou = 0
for i in range(Q):
    if Query[i][0] == "1":
        sentou += 1
    if Query[i][0] == "2":
        if Query[i][1] == "1":
            if sentou % 2:
                ans = ans + Query[i][2]
            else:
                ans = Query[i][2] + ans
        if Query[i][1] == "2":
            if sentou % 2:
                ans = Query[i][2] + ans
            else:
                ans = ans + Query[i][2]
if sentou % 2:
    print(ans[::-1])
else:
    print(ans)

Fixed submission:
from collections import deque
S = deque([input()])
Q = int(input())
Query = list(input().split() for i in range(Q))
sentou = 0
for i in range(Q):
    if Query[i][0] == "1":
        sentou += 1
    if Query[i][0] == "2":
        if Query[i][1] == "1":
            if sentou % 2:
                S.append(Query[i][2])
            else:
                S.appendleft(Query[i][2])
        if Query[i][1] == "2":
            if sentou % 2:
                S.appendleft(Query[i][2])
            else:
                S.append(Query[i][2])
ans = ""
for i in S:
    ans += i
if sentou % 2:
    print(ans[::-1])
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = list(input().split() for i in range(Q))
ans = S
for i in range(Q):
    if Query[i][0] == "1":
        ans = ans[::-1]
    if Query[i][0] == "2":
        if Query[i][1] == "1":
            ans = Query[i][2] + ans
        if Query[i][1] == "2":
            ans = ans + Query[i][2]
print(ans)

Fixed submission:
from collections import deque
S = deque([input()])
Q = int(input())
Query = list(input().split() for i in range(Q))
sentou = 0
for i in range(Q):
    if Query[i][0] == "1":
        sentou += 1
    if Query[i][0] == "2":
        if Query[i][1] == "1":
            if sentou % 2:
                S.append(Query[i][2])
            else:
                S.appendleft(Query[i][2])
        if Query[i][1] == "2":
            if sentou % 2:
                S.appendleft(Query[i][2])
            else:
                S.append(Query[i][2])
ans = ""
for i in S:
    ans += i
if sentou % 2:
    print(ans[::-1])
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = list(input().split() for i in range(Q))
ans = S
for i in range(Q):
    if Query[i][0] == "1":
        ans = ans[::-1]
    if Query[i][0] == "2":
        if Query[i][1] == "1":
            ans = Query[i][2] + ans
        if Query[i][1] == "2":
            ans = ans + Query[i][2]
print(ans)

Fixed submission:
from collections import deque
S = deque([input()])
Q = int(input())
Query = list(input().split() for i in range(Q))
sentou = 0
for i in range(Q):
    if Query[i][0] == "1":
        sentou += 1
    if Query[i][0] == "2":
        if Query[i][1] == "1":
            if sentou % 2:
                S.append(Query[i][2])
            else:
                S.appendleft(Query[i][2])
        if Query[i][1] == "2":
            if sentou % 2:
                S.appendleft(Query[i][2])
            else:
                S.append(Query[i][2])
ans = ""
for i in S:
    ans += i
if sentou % 2:
    print(ans[::-1])
else:
    print(ans)