Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
s = input()
q = int(input())
cnt = 0
for i in range(q):
    query = input().split()
    if len(query) == 1:
        cnt += 1
    else:
        if cnt % 2 == 0:
            if query[1] == "1":
                s = query[2] + s
            else:
                s += query[2]
        else:
            if query[1] == "1":
                s += query[2]
            else:
                s = query[2] + s

if cnt % 2 != 0:
    s = s[::-1]

print(s)


Fixed submission:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60

# ここから書き始める
s = input()
q = int(input())
cnt = 0
left = []
right = []
for i in range(q):
    query = input().split()
    if len(query) == 1:
        cnt += 1
    else:
        f = query[1]
        c = query[2]
        if cnt % 2 == 0:
            if f == "1":
                # s = c + s
                left.append(c)
            else:
                # s += c
                right.append(c)
        else:
            if f == "1":
                # s += c
                right.append(c)
            else:
                # s = query[2] + s
                left.append(c)

left = left[::-1]
right = "".join(right)
left = "".join(left)
ans = "".join([left, s, right])
# print(right, s, left)
if cnt % 2 != 0:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
s = input()
n = int(input())
for i in range(n):
    a = input().split()
    # print(a)
    if len(a) == 1:
        s = s[::-1]
    elif a[1] == "1":
        s = a[2] + s
        # print(a[2])
    else:
        s = s + a[2]
    # print(s)
print(s)


Fixed submission:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce

sys.setrecursionlimit(4100000)
from functools import lru_cache

INF = 1 << 60

# ここから書き始める
s = input()
q = int(input())
cnt = 0
left = []
right = []
for i in range(q):
    query = input().split()
    if len(query) == 1:
        cnt += 1
    else:
        f = query[1]
        c = query[2]
        if cnt % 2 == 0:
            if f == "1":
                # s = c + s
                left.append(c)
            else:
                # s += c
                right.append(c)
        else:
            if f == "1":
                # s += c
                right.append(c)
            else:
                # s = query[2] + s
                left.append(c)

left = left[::-1]
right = "".join(right)
left = "".join(left)
ans = "".join([left, s, right])
# print(right, s, left)
if cnt % 2 != 0:
    ans = ans[::-1]

print(ans)