Buggy python submission (verdict: Time Limit Exceeded):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    S = sr()
    Q = ir()
    rev = 1
    for i in range(Q):
        T = list(sr().split())
        if int(T[0]) == 1:
            rev *= -1
        else:
            x, F, C = T
            if int(F) == 1:
                if rev == 1:
                    S = C+S
                else:
                    S = S+C
            else:
                if rev == 1:
                    S = S+C
                else:
                    S = C+S
    if rev == -1:
        S = S[::-1]
    print(S)
resolve()

Fixed submission:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    S = deque(sr())
    Q = ir()
    rev = 1
    for i in range(Q):
        T = list(sr().split())
        if int(T[0]) == 1:
            rev *= -1
        else:
            x, F, C = T
            if int(F) == 1:
                if rev == 1:
                    S.appendleft(C)
                else:
                    S.append(C)
            else:
                if rev == 1:
                    S.append(C)
                else:
                    S.appendleft(C)
    if rev == -1:
        S.reverse()
    print(*S, sep='')
resolve()

Buggy python submission (verdict: Runtime Error):
mport sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    S = deque(list(sr().split()), maxlen=1000000)
    Q = ir()
    rev = 1
    for i in range(Q):
        T = list(sr().split())
        if int(T[0]) == 1:
            rev *= -1
        else:
            x, F, C = T
            if int(F) == 1:
                if rev == 1:
                    S.appendleft(C)
                else:
                    S.append(C)
            else:
                if rev == 1:
                    S.append(C)
                else:
                    S.appendleft(C)
    if rev == -1:
        S.reverse()
    print(*S, sep='')
resolve()

Fixed submission:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    S = deque(sr())
    Q = ir()
    rev = 1
    for i in range(Q):
        T = list(sr().split())
        if int(T[0]) == 1:
            rev *= -1
        else:
            x, F, C = T
            if int(F) == 1:
                if rev == 1:
                    S.appendleft(C)
                else:
                    S.append(C)
            else:
                if rev == 1:
                    S.append(C)
                else:
                    S.appendleft(C)
    if rev == -1:
        S.reverse()
    print(*S, sep='')
resolve()

Buggy python submission (verdict: Runtime Error):
mport sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    S = deque(list(sr().split()), maxlen=1000000)
    Q = ir()
    rev = 1
    for i in range(Q):
        T = list(sr().split())
        if int(T[0]) == 1:
            rev *= -1
        else:
            x, F, C = T
            if int(F) == 1:
                if rev == 1:
                    S.appendleft(C)
                else:
                    S.append(C)
            else:
                if rev == 1:
                    S.append(C)
                else:
                    S.appendleft(C)
    if rev == -1:
        S.reverse()
    print(*S, sep='')
resolve()

Fixed submission:
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
from collections import deque
def resolve():
    S = deque(sr())
    Q = ir()
    rev = 1
    for i in range(Q):
        T = list(sr().split())
        if int(T[0]) == 1:
            rev *= -1
        else:
            x, F, C = T
            if int(F) == 1:
                if rev == 1:
                    S.appendleft(C)
                else:
                    S.append(C)
            else:
                if rev == 1:
                    S.append(C)
                else:
                    S.appendleft(C)
    if rev == -1:
        S.reverse()
    print(*S, sep='')
resolve()