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

s = list(input())
q = int(input())

for i in range(q):
    query = input()
    if query == "1":
        s = s[::-1]
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            a = deque(s)
            a.appendleft(q2_2)
            s = list(a)
        else:
            s.append(q2_2)
print("".join(s))

Fixed submission:
# -*- coding: utf-8 -*-
from collections import deque

s = list(input())
q = int(input())

a = deque(s)
reverse = False

for i in range(q):
    query = input()
    if query == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            if reverse:
                a.append(q2_2)
            else:
                a.appendleft(q2_2)
        else:
            if reverse:
                a.appendleft(q2_2)
            else:
                a.append(q2_2)

s = list(a)
if reverse:
    s = s[::-1]
    print("".join(s))
else:
    print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
s = list(input())
q = int(input())

for i in range(q):
    query = input()
    if query == "1":
        s = s[::-1]
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            s.insert(0, q2_2)
        else:
            s.append(q2_2)
print("".join(s))

Fixed submission:
# -*- coding: utf-8 -*-
from collections import deque

s = list(input())
q = int(input())

a = deque(s)
reverse = False

for i in range(q):
    query = input()
    if query == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            if reverse:
                a.append(q2_2)
            else:
                a.appendleft(q2_2)
        else:
            if reverse:
                a.appendleft(q2_2)
            else:
                a.append(q2_2)

s = list(a)
if reverse:
    s = s[::-1]
    print("".join(s))
else:
    print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
s = input()
q = int(input())

for i in range(q):
    query = input()
    if query == "1":
        s = s[::-1]
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            s = q2_2+s
        else:
            s += q2_2
print(s)

Fixed submission:
# -*- coding: utf-8 -*-
from collections import deque

s = list(input())
q = int(input())

a = deque(s)
reverse = False

for i in range(q):
    query = input()
    if query == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            if reverse:
                a.append(q2_2)
            else:
                a.appendleft(q2_2)
        else:
            if reverse:
                a.appendleft(q2_2)
            else:
                a.append(q2_2)

s = list(a)
if reverse:
    s = s[::-1]
    print("".join(s))
else:
    print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
s = input()
q = int(input())

for i in range(q):
    query = input()
    if query == "1":
        s = s[::-1]
    else:
        q2 = query.split()
        if q2[1] == "1":
            s = q2[2]+s
        else:
            s = s + q2[2]
print(s)

Fixed submission:
# -*- coding: utf-8 -*-
from collections import deque

s = list(input())
q = int(input())

a = deque(s)
reverse = False

for i in range(q):
    query = input()
    if query == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            if reverse:
                a.append(q2_2)
            else:
                a.appendleft(q2_2)
        else:
            if reverse:
                a.appendleft(q2_2)
            else:
                a.append(q2_2)

s = list(a)
if reverse:
    s = s[::-1]
    print("".join(s))
else:
    print("".join(s))

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

s = input()
q = int(input())
query = ["" for _ in range(q)]

for i in range(q):
    query = input()
    if query == "1":
        s = "".join(list(reversed(s)))
        #print(s)
    else:
        q2 = query.split()
        if q2[1] == "1":
            s = q2[2]+s
        else:
            s = s + q2[2]
        #print(s)

print(s)



Fixed submission:
# -*- coding: utf-8 -*-
from collections import deque

s = list(input())
q = int(input())

a = deque(s)
reverse = False

for i in range(q):
    query = input()
    if query == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    else:
        x, q2_1, q2_2 = query.split()
        if q2_1 == "1":
            if reverse:
                a.append(q2_2)
            else:
                a.appendleft(q2_2)
        else:
            if reverse:
                a.appendleft(q2_2)
            else:
                a.append(q2_2)

s = list(a)
if reverse:
    s = s[::-1]
    print("".join(s))
else:
    print("".join(s))