Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())


flg = True
for i in range(Q):
    que = input()
    if que == "1":
        if flg:
            flg = False
        else:
            flg = True
    else:
        j, F, C = que.split()
        if int(F) == 1:
            if flg:
                S = C + S
            else:
                S = S + C
        else:
            if flg:
                S = S + C
            else:
                S = C + S

if flg:
    print(S)
else:
    print(S[::-1])

Fixed submission:
from collections import deque

S = input()
Q = int(input())

Sq = deque(S)


flg = True
for i in range(Q):
    que = input()
    if que == "1":
        if flg:
            flg = False
        else:
            flg = True
    else:
        j, F, C = que.split()
        if int(F) == 1:
            if flg:
                Sq.appendleft(C)
            else:
                Sq.append(C)
        else:
            if flg:
                Sq.append(C)
            else:
                Sq.appendleft(C)

if flg:
    for i in Sq:
        print(i, end="")
else:
    Sq.reverse()
    for i in Sq:
        print(i, end="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())


flg = True
for i in range(Q):
    que = input()
    if que == "1":
        if flg:
            flg = False
        else:
            flg = True
    else:
        j, F, C = que.split()
        if int(F) == 1:
            if flg:
                S = [C] + S
            else:
                S = S + [C]
        else:
            if flg:
                S = S + [C]
            else:
                S = [C] + S

if flg:
    for s in S:
        print(s, end="")
else:
    for s in reversed(S):
        print(s, end="")

Fixed submission:
from collections import deque

S = input()
Q = int(input())

Sq = deque(S)


flg = True
for i in range(Q):
    que = input()
    if que == "1":
        if flg:
            flg = False
        else:
            flg = True
    else:
        j, F, C = que.split()
        if int(F) == 1:
            if flg:
                Sq.appendleft(C)
            else:
                Sq.append(C)
        else:
            if flg:
                Sq.append(C)
            else:
                Sq.appendleft(C)

if flg:
    for i in Sq:
        print(i, end="")
else:
    Sq.reverse()
    for i in Sq:
        print(i, end="")

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())

for i in range(Q):
    que = input()
    if que == "1":
        S.reverse()
    else:
        j, F, C = que.split()
        if int(F) == 1:
            S = [C] + S
        else:
            S = S + [C]

for s in S:
    print(s, end="")

Fixed submission:
from collections import deque

S = input()
Q = int(input())

Sq = deque(S)


flg = True
for i in range(Q):
    que = input()
    if que == "1":
        if flg:
            flg = False
        else:
            flg = True
    else:
        j, F, C = que.split()
        if int(F) == 1:
            if flg:
                Sq.appendleft(C)
            else:
                Sq.append(C)
        else:
            if flg:
                Sq.append(C)
            else:
                Sq.appendleft(C)

if flg:
    for i in Sq:
        print(i, end="")
else:
    Sq.reverse()
    for i in Sq:
        print(i, end="")