Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
from collections import deque

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

querys = []
op1_cnt = 0
op2_cnt = 0
prefix = deque()
suffix = deque()
for i in range(Q):
    query = input()
    if len(query) == 1:
        op1_cnt += 1

        if op2_cnt != 0:
            prefix.extend(S)
            prefix.extend(suffix)
            S = ''.join(prefix)
            prefix.clear()
            suffix.clear()
            op2_cnt = 0

    else:
        op2_cnt += 1

        if op1_cnt % 2 != 0:
            S = S[::-1]

        op1_cnt = 0

        t, F, C = query.split()
        if F == "1":
            prefix.appendleft(C)
        else:
            suffix.append(C)

if op1_cnt % 2 != 0:
    S = S[::-1]

if op2_cnt != 0:
    prefix.extend(S)
    prefix.extend(suffix)
    S = ''.join(prefix)


print(S)


Fixed submission:
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

reverse = 0
head = []
tail = []
for i in range(Q):
    query = input()
    if len(query) == 1:
        reverse = (reverse + 1) % 2

    else:
        t, F, C = query.split()
        if reverse == 0:
            if F == "1":
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == "1":
                tail.append(C)
            else:
                head.append(C)

if reverse == 0:
    S = ''.join(head[::-1] + list(S) + tail)
else:
    S = ''.join(tail[::-1] + list(S[::-1]) + head)


print(S)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from collenctions import deque

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

querys = []
op1_cnt = 0
op2_cnt = 0
prefix = deque()
suffix = deque()
for i in range(Q):
    query = input()
    if len(query) == 1:
        op1_cnt += 1

        if op2_cnt != 0:
            prefix.extend(S)
            prefix.extend(suffix)
            S = ''.join(prefix)
            prefix.clear()
            suffix.clear()
            op2_cnt = 0

    else:
        op2_cnt += 1

        if op1_cnt % 2 != 0:
            S = S[::-1]

        op1_cnt = 0

        t, F, C = query.split()
        if F == "1":
            prefix.appendleft(C)
        else:
            suffix.append(C)

if op1_cnt % 2 != 0:
    S = S[::-1]

if op2_cnt != 0:
    prefix.extend(S)
    prefix.extend(suffix)
    S = ''.join(prefix)


print(S)


Fixed submission:
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

reverse = 0
head = []
tail = []
for i in range(Q):
    query = input()
    if len(query) == 1:
        reverse = (reverse + 1) % 2

    else:
        t, F, C = query.split()
        if reverse == 0:
            if F == "1":
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == "1":
                tail.append(C)
            else:
                head.append(C)

if reverse == 0:
    S = ''.join(head[::-1] + list(S) + tail)
else:
    S = ''.join(tail[::-1] + list(S[::-1]) + head)


print(S)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

querys = []
op1_cnt = 0
op2_cnt = 0
op2_C = {"1": [], "2": []}
for i in range(Q):
    query = input()
    if len(query) == 1:
        op1_cnt += 1

        if op2_cnt != 0:
            args = op2_C["1"][::-1]
            args.extend(S)
            args.extend(op2_C["2"])
            S = ''.join(args)
            op2_C = {"1": [], "2": []}
            op2_cnt = 0

    else:
        op2_cnt += 1

        if op1_cnt % 2 != 0:
            S = S[::-1]

        op1_cnt = 0

        t, F, C = query.split()
        op2_C[F].append(C)

if op1_cnt % 2 != 0:
    S = S[::-1]

if op2_cnt != 0:
    args = op2_C["1"][::-1]
    args.extend(S)
    args.extend(op2_C["2"])
    S = ''.join(args)


print(S)


Fixed submission:
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

reverse = 0
head = []
tail = []
for i in range(Q):
    query = input()
    if len(query) == 1:
        reverse = (reverse + 1) % 2

    else:
        t, F, C = query.split()
        if reverse == 0:
            if F == "1":
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == "1":
                tail.append(C)
            else:
                head.append(C)

if reverse == 0:
    S = ''.join(head[::-1] + list(S) + tail)
else:
    S = ''.join(tail[::-1] + list(S[::-1]) + head)


print(S)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

querys = []
op1_cnt = 0
op2_cnt = 0
op2_C = {"1": [], "2": []}
for i in range(Q):
    query = input()
    if len(query) == 1:
        op1_cnt += 1

        if op2_cnt != 0:
            args = op2_C["1"][::-1]
            args.extend(S)
            args.extend(op2_C["2"])
            S = ''.join(args)
            op2_C = {"1": [], "2": []}
            op2_cnt = 0

    else:
        op2_cnt += 1

        if op1_cnt % 2 != 0 and len(S) != 1:
            S = S[::-1]

        op1_cnt = 0

        t, F, C = query.split()
        op2_C[F].append(C)

if op1_cnt % 2 != 0 and len(S) != 1:
    S = S[::-1]

if op2_cnt != 0:
    args = op2_C["1"][::-1]
    args.extend(S)
    args.extend(op2_C["2"])
    S = ''.join(args)


print(S)


Fixed submission:
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

reverse = 0
head = []
tail = []
for i in range(Q):
    query = input()
    if len(query) == 1:
        reverse = (reverse + 1) % 2

    else:
        t, F, C = query.split()
        if reverse == 0:
            if F == "1":
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == "1":
                tail.append(C)
            else:
                head.append(C)

if reverse == 0:
    S = ''.join(head[::-1] + list(S) + tail)
else:
    S = ''.join(tail[::-1] + list(S[::-1]) + head)


print(S)