Buggy python submission (verdict: Time Limit Exceeded):
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                S = each[2] + S
            else:
                S = S + each[2]
        else:
            if hanten == -1:
                S = S + each[2]
            else:
                S = each[2] + S

if hanten == 1:
    S = S[::-1]

print(S)

Fixed submission:
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
atama = ""
shiri = ""
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                atama = atama + each[2]
            else:
                shiri = shiri + each[2]
        else:
            if hanten == -1:
                shiri = shiri + each[2]
            else:
                atama = atama + each[2]

atama = atama[::-1]
ans = atama + S + shiri
if hanten == 1:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                S = each[2] + S
            else:
                S = S + each[2]
        else:
            if hanten == -1:
                S = S + each[2]
            else:
                S = each[2] + S

if hanten == 1:
    S = S[::-1]

print(S)

Fixed submission:
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
atama = ""
shiri = ""
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                atama = atama + each[2]
            else:
                shiri = shiri + each[2]
        else:
            if hanten == -1:
                shiri = shiri + each[2]
            else:
                atama = atama + each[2]

atama = atama[::-1]
ans = atama + S + shiri
if hanten == 1:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        S = S[::-1]
    else:
        if each[1] == "1":
            S = each[2] + S
        else:
            S = S + each[2]

print(S)

Fixed submission:
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
atama = ""
shiri = ""
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                atama = atama + each[2]
            else:
                shiri = shiri + each[2]
        else:
            if hanten == -1:
                shiri = shiri + each[2]
            else:
                atama = atama + each[2]

atama = atama[::-1]
ans = atama + S + shiri
if hanten == 1:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
quantity = int(input())
for row in range(quantity):
    each = input().split()
    if each[0] == "1":
        S = S[::-1]
    else:
        if each[1] == "1":
            S = each[2] + S
        else:
            S = S + each[2]

print(S)

Fixed submission:
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
atama = ""
shiri = ""
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                atama = atama + each[2]
            else:
                shiri = shiri + each[2]
        else:
            if hanten == -1:
                shiri = shiri + each[2]
            else:
                atama = atama + each[2]

atama = atama[::-1]
ans = atama + S + shiri
if hanten == 1:
    ans = ans[::-1]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
quantity = int(input())
for row in range(quantity):
    each = input().split()
    if each[0] == "1":
        S = S[::-1]
    else:
        if each[1] == "1":
            S = each[2] + S
        else:
            S = S + each[2]

print(S)

Fixed submission:
S = input()
quantity = int(input())
L = [input().split() for i in range(quantity)]
hanten = -1
atama = ""
shiri = ""
for row in range(quantity):
    each = L[row]
    if each[0] == "1":
        hanten = hanten * -1
    else:
        if each[1] == "1":
            if hanten == -1:
                atama = atama + each[2]
            else:
                shiri = shiri + each[2]
        else:
            if hanten == -1:
                shiri = shiri + each[2]
            else:
                atama = atama + each[2]

atama = atama[::-1]
ans = atama + S + shiri
if hanten == 1:
    ans = ans[::-1]

print(ans)