Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
f = ""
b = ""
forward = True
for _ in range(q):
    que = list(input().split())
    if int(que[0]) == 1:
        if forward:
            forward = False
        else:
            forward = True
    else:
        if (int(que[1]) == 1 and forward) or (int(que[1]) == 2 and not forward):
            f+=que[2]
        else:
            b+=que[2]

if forward:
    ff = ""
    for i in reversed(range(len(f))):
        ff += f[i]
    
    print(ff+s+b)
else:
    bb = ""
    for i in reversed(range(len(b))):
        bb += b[i]
    ss = ""
    for i in reversed(range(len(s))):
        ss += s[i]
    print(bb+ss+f)

Fixed submission:
from collections import deque
s = input()
q = int(input())
f = ""
b = ""
forward = True
for _ in range(q):
    que = list(input().split())
    if int(que[0]) == 1:
        if forward:
            forward = False
        else:
            forward = True
    else:
        if (int(que[1]) == 1 and forward) or (int(que[1]) == 2 and not forward):
            f+=que[2]
        else:
            b+=que[2]

if forward:
    print(f[::-1]+s+b)
else:

    print(b[::-1]+s[::-1]+f)

Buggy python submission (verdict: Time Limit Exceeded):
s = [input()]
q = int(input())
forward = True
for _ in range(q):
    que = list(input().split())
    if int(que[0]) == 1:
        if forward:
            forward = False
        else:
            forward = True
    else:
        if (int(que[1]) == 1 and forward) or (int(que[1]) == 2 and not forward):
            s = [que[2]] + s
        else:
            s.append(que[2])
if forward:
    print("".join(s))
else:
    ss = "".join(s)
    ans = ""
    for i in reversed(range(len(ss))):
        ans += ss[i]
    print(ans)

Fixed submission:
from collections import deque
s = input()
q = int(input())
f = ""
b = ""
forward = True
for _ in range(q):
    que = list(input().split())
    if int(que[0]) == 1:
        if forward:
            forward = False
        else:
            forward = True
    else:
        if (int(que[1]) == 1 and forward) or (int(que[1]) == 2 and not forward):
            f+=que[2]
        else:
            b+=que[2]

if forward:
    print(f[::-1]+s+b)
else:

    print(b[::-1]+s[::-1]+f)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
forward = True
for _ in range(q):
    que = list(input().split())
    if int(que[0]) == 1:
        if forward:
            forward = False
        else:
            forward = True
    else:
        if (int(que[1]) == 1 and forward) or (int(que[1]) == 2 and not forward):
            s = [que[2]] + s
        else:
            s .append(que[2])
if forward:
    print("".join(s))
else:
    print("".join(reversed(s)))

Fixed submission:
from collections import deque
s = input()
q = int(input())
f = ""
b = ""
forward = True
for _ in range(q):
    que = list(input().split())
    if int(que[0]) == 1:
        if forward:
            forward = False
        else:
            forward = True
    else:
        if (int(que[1]) == 1 and forward) or (int(que[1]) == 2 and not forward):
            f+=que[2]
        else:
            b+=que[2]

if forward:
    print(f[::-1]+s+b)
else:

    print(b[::-1]+s[::-1]+f)