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

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

Fixed submission:
s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

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

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            s = q[2] + s
        else:
            s = s + q[2]
    else:
        if flag == 0:
            s = s + q[2]
        else:
            s = q[2] + s


if flag == 0:
    print(s)
elif flag == 1:
    print(s[::-1])

Fixed submission:
s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

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

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            s = q[2] + s
        else:
            s = s + q[2]
    else:
        if flag == 0:
            s = s + q[2]
        else:
            s = q[2] + s


if flag == 0:
    print(s)
elif flag == 1:
    print(s[::-1])

Fixed submission:
s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

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

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1 and q[0] == "1":
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            s = q[2] + s
        elif flag == 1:
            s = s + q[2]
    elif q[1] == "2":
        if flag == 0:
            s = s + q[2]
        elif flag == 1:
            s = q[2] + s


if flag == 0:
    print(s)
elif flag == 1:
    print(s[::-1])

Fixed submission:
s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
n = int(input())
 
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1 and q[0] == "1":
        s = s[::-1]
    elif q[1] == "1":
        s = q[2] + s
    elif q[1] == "2":
        s = s + q[2]
 
 
print(s)

Fixed submission:
s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])

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

for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1 and q[0] == "1":
        s = s[::-1]
    elif q[1] == "1":
        s = q[2] + s
    elif q[1] == "2":
        s = s + q[2]


print(s)

Fixed submission:
s = str(input())
n = int(input())

right = ""
left = ""

flag = 0
for i in range(n):
    q = list(map(str,input().split()))
    if len(q) == 1:
        flag = 1 - flag 
    elif q[1] == "1":
        if flag == 0:
            left = q[2] + left
        else:
            right = right + q[2]
    else:
        if flag == 0:
            right = right + q[2]
        else:
            left = q[2] + left


if flag == 0:
    print(left + s + right)
elif flag == 1:
    print(right[::-1] + s[::-1] + left[::-1])