Buggy python submission (verdict: Runtime Error):
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        c = deque(c)
        if num == 0:
            if f == '1':
                s = c + s
            else:
                s = s + c
        else:
            if f == '2':
                s = c + s
            else:
                s = s + c
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
s = sys.stdin.readline().rstrip()
q = int(sys.stdin.readline().rstrip())

for _ in range(q):
    t = sys.stdin.readline().rstrip()
    if t == '1':
        s = s[::-1]
    else:
        t, f, c = t.split()
        if f == '1':
            s = c + s
        else:
            s = s + c

print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

num = 0

import sys

for _ in range(q):
    t = sys.stdin.readline().rstrip()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s = c + s
            else:
                s = s + c
        else:
            if f == '2':
                s = c + s
            else:
                s = s + c

if num == 1:
    s = s[::-1]

print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

num = 0

import sys

for _ in range(q):
    t = sys.stdin.readline().rstrip()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s = c + s
            else:
                s = s + c
        else:
            if f == '2':
                s = c + s
            else:
                s = s + c

if num == 1:
    s = s[::-1]

print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

num = 0

import sys

for _ in range(q):
    t = sys.stdin.readline().rstrip()
    if t == '1':
        num += 1
    else:
        t, f, c = t.split()
        if num%2 == 0:
            if f == '1':
                s = c + s
            else:
                s = s + c
        else:
            if f == '2':
                s = c + s
            else:
                s = s + c

if num%2 == 1:
    s = s[::-1]
print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

num = 0

for _ in range(q):
    t = input()
    if t == '1':
        num += 1
    else:
        t, f, c = t.split()
        if num%2 == 0:
            if f == '1':
                s = c + s
            else:
                s = s + c
        else:
            if f == '2':
                s = c + s
            else:
                s = s + c

if num%2 == 1:
    s = s[::-1]
print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

num = 0

for _ in range(q):
    t = input()
    if t == '1':
        num += 1
    else:
        t, f, c = t.split()
        if num%2 == 0:
            if f == '1':
                s = c + s
            else:
                s = s + c
        else:
            if f == '2':
                s = c + s
            else:
                s = s + c

if num%2 == 1:
    s = s[::-1]
print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for _ in range(q):
    t = input()
    if t == '1':
        s = s[::-1]
    else:
        t, f, c = t.split()
        if f == '1':
            s = c + s
        else:
            s = s + c

print(s)

Fixed submission:
#TLE
from collections import deque
s = deque(input())
q = int(input())
num = 0
for _ in range(q):
    t = input()
    if t == '1':
        if num == 0:
            num = 1
        else:
            num = 0
    else:
        t, f, c = t.split()
        if num == 0:
            if f == '1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f == '2':
                s.appendleft(c)
            else:
                s.append(c)
s = ''.join(s)
if num == 1:
    s = s[::-1]
print(s)