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

s = list(input())
q = int(input())
ans = deque(s)
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        ans.reverse()
    else:
        if arr[1] == '1':
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
print(*ans, sep='')

Fixed submission:
from collections import deque


s = list(input())
q = int(input())
ans = deque(s)
cnt = 0
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        cnt += 1
        cnt %= 2
    else:
        if (arr[1] == '1' and cnt == 0) or (arr[1] == '2' and cnt == 1):
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
if cnt == 0:
    print(*ans, sep='')
else:
    ans.reverse()
    print(*ans, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ans = s
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        ans = ans[::-1]
    else:
        if arr[1] == '1':
            ans = arr[2] + ans
        else:
            ans += arr[2]
print(ans)


Fixed submission:
from collections import deque


s = list(input())
q = int(input())
ans = deque(s)
cnt = 0
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        cnt += 1
        cnt %= 2
    else:
        if (arr[1] == '1' and cnt == 0) or (arr[1] == '2' and cnt == 1):
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
if cnt == 0:
    print(*ans, sep='')
else:
    ans.reverse()
    print(*ans, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ans = s
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        ans = ans[::-1]
    else:
        if arr[1] == '1':
            ans = arr[2] + ans
        else:
            ans += arr[2]
print(ans)


Fixed submission:
from collections import deque


s = list(input())
q = int(input())
ans = deque(s)
cnt = 0
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        cnt += 1
        cnt %= 2
    else:
        if (arr[1] == '1' and cnt == 0) or (arr[1] == '2' and cnt == 1):
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
if cnt == 0:
    print(*ans, sep='')
else:
    ans.reverse()
    print(*ans, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
arr = [list(map(str, input().split())) for _ in range(q)]
ans = s
for i in range(q):
    if arr[i][0] == '1':
        ans = ans[::-1]
    else:
        if arr[i][1] == '1':
            ans = arr[i][2] + ans
        else:
            ans += arr[i][2]
print(ans)


Fixed submission:
from collections import deque


s = list(input())
q = int(input())
ans = deque(s)
cnt = 0
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        cnt += 1
        cnt %= 2
    else:
        if (arr[1] == '1' and cnt == 0) or (arr[1] == '2' and cnt == 1):
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
if cnt == 0:
    print(*ans, sep='')
else:
    ans.reverse()
    print(*ans, sep='')