Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
Q = int(input())
front = 1
for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        front *= -1
    else:
        if q[1] == "1":
            if front == 1:
                s = q[2] + s
            else:
                s = s + q[2]             
        else:
            if front == 1:
                s = s + q[2]
            else:
                s = q[2] + s

if front == -1:
    s = s[::-1]
print(s)

Fixed submission:
s = str(input())
Q = int(input())
forward = 1
front = ""
back = ""

for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        forward *= -1
    else:
        if q[1] == "1":
            if forward == 1:
                front = q[2] + front
            else:
                back = back + q[2]        
        else:
            if forward == 1:
                back = back + q[2]
            else:
                front = q[2] + front

s = front + s + back
if forward == -1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
Q = int(input())
front = 1
for i in range(Q):
    q = list(map(str, input().split()))
    if q[0] == "1":
        front *= -1
    else:
        if q[1] == "1":
            if front == 1:
                s = q[2] + s
            else:
                s = s + q[2]             
        else:
            if front == 1:
                s = s + q[2]
            else:
                s = q[2] + s

if front == -1:
    s = s[::-1]
print(s)

Fixed submission:
s = str(input())
Q = int(input())
forward = 1
front = ""
back = ""

for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        forward *= -1
    else:
        if q[1] == "1":
            if forward == 1:
                front = q[2] + front
            else:
                back = back + q[2]        
        else:
            if forward == 1:
                back = back + q[2]
            else:
                front = q[2] + front

s = front + s + back
if forward == -1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
Q = int(input())
front = 1
for i in range(Q):
    q = list(map(str, input().split()))
    if q[0] == "1":
        front *= -1
    else:
        if q[1] == "1":
            if front == 1:
                s = q[2] + s
            else:
                s = s + q[2]             
        else:
            if front == 1:
                s = s + q[2]
            else:
                s = q[2] + s

if front == -1:
    s = s[::-1]
print(s)

Fixed submission:
s = str(input())
Q = int(input())
forward = 1
front = ""
back = ""

for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        forward *= -1
    else:
        if q[1] == "1":
            if forward == 1:
                front = q[2] + front
            else:
                back = back + q[2]        
        else:
            if forward == 1:
                back = back + q[2]
            else:
                front = q[2] + front

s = front + s + back
if forward == -1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
s = str(input())
Q = int(input())
front = 1
for i in range(Q):
    q = list(map(str, input().split()))
    if q[0] == "1":
        front *= -1
    else:
        if q[1] == "1":
            if front == 1
                s = q[2] + s
            else:
                s = s + q[2]             
        else:
            if front == 1
                s = s + q[2]
            else:
                s = q[2] + s

if front == -1:
    s = s[::-1]
print(s)

Fixed submission:
s = str(input())
Q = int(input())
forward = 1
front = ""
back = ""

for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        forward *= -1
    else:
        if q[1] == "1":
            if forward == 1:
                front = q[2] + front
            else:
                back = back + q[2]        
        else:
            if forward == 1:
                back = back + q[2]
            else:
                front = q[2] + front

s = front + s + back
if forward == -1:
    s = s[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
s = input()
Q = int(input())
for i in range(Q):
    q = list(map(str, input().split())
    if q[0] == "1":
        if len(s) > 1:
            s = s[-1] + s[1:-1] + s[0]
    else:
        if q[1] == "1":
            s = q[2] + s 
        else:
            s = s + q[2]
print(s)

Fixed submission:
s = str(input())
Q = int(input())
forward = 1
front = ""
back = ""

for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        forward *= -1
    else:
        if q[1] == "1":
            if forward == 1:
                front = q[2] + front
            else:
                back = back + q[2]        
        else:
            if forward == 1:
                back = back + q[2]
            else:
                front = q[2] + front

s = front + s + back
if forward == -1:
    s = s[::-1]
print(s)