Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
    st = input()
    q = int(input())
    qnt_inv = 0
    for _ in range(q):
        t = sys.stdin.read(1)
        if t == '2':
            if qnt_inv % 2 == 1:
                st = st[::-1]
                qnt_inv = 0
            f, a = input().split()
            if f == '1':
                st = a + st
            else:
                st = st + a
        else:
            t = sys.stdin.read(1)
            qnt_inv += 1

    if qnt_inv > 0 and qnt_inv % 2 == 1:
        st = st[::-1]
    print(st)

main()

Fixed submission:
"""
    Author: _YL_
"""
s = input()
n = int(input())

flip = 0
left = 0
right = 1
strs = ["", ""]

i = 0
while i < n:
    lst = input().split()

    if lst[0] == "1":
        flip += 1
        left = 0 if left == 1 else 1
        right = 0 if right == 1 else 1
    elif lst[1] == "1":
        strs[left] += lst[2]
    else:
        strs[right] += lst[2]
    i += 1

if flip % 2 == 1:
    s = s[::-1]
    
s = strs[left][::-1] + s + strs[right]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
    st = input()
    q = int(input())

    for _ in range(q):
        t = sys.stdin.read(1)
        if t == '2':
            f, a = input().split()
            if f == '1':
                st = a + st
            else:
                st = st + a
        else:
            t = sys.stdin.read(1)
            st = st[::-1]

    print(st)

main()

Fixed submission:
"""
    Author: _YL_
"""
s = input()
n = int(input())

flip = 0
left = 0
right = 1
strs = ["", ""]

i = 0
while i < n:
    lst = input().split()

    if lst[0] == "1":
        flip += 1
        left = 0 if left == 1 else 1
        right = 0 if right == 1 else 1
    elif lst[1] == "1":
        strs[left] += lst[2]
    else:
        strs[right] += lst[2]
    i += 1

if flip % 2 == 1:
    s = s[::-1]
    
s = strs[left][::-1] + s + strs[right]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
str = input()
Q = int(input())
left = []
right = []
flag = 1
for _ in range(Q):
    line = input().split()
    op1 = int(line[0])
    if op1 == 1:
        flag = -flag
    else:
        op2 = int(line[1])
        char = line[2]
        if op2 == 1 and flag == 1:
            left.append(char)
        elif op2 == 1 and flag == -1:
            right.append(char)
        elif op2 == 2 and flag == 1:
            right.append(char)
        elif op2 == 2 and flag == -1:
            left.append(char)

if flag == -1:
    str = str[::-1]
    for l in left:
        str += l
    for r in right:
        str = r + str
else:
    for l in left:
        str = l + str
    for r in right:
        str += r

print(str)


Fixed submission:
"""
    Author: _YL_
"""
s = input()
n = int(input())

flip = 0
left = 0
right = 1
strs = ["", ""]

i = 0
while i < n:
    lst = input().split()

    if lst[0] == "1":
        flip += 1
        left = 0 if left == 1 else 1
        right = 0 if right == 1 else 1
    elif lst[1] == "1":
        strs[left] += lst[2]
    else:
        strs[right] += lst[2]
    i += 1

if flip % 2 == 1:
    s = s[::-1]
    
s = strs[left][::-1] + s + strs[right]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
str = input()
Q = int(input())
for _ in range(Q):
    line = input().split()
    op1 = int(line[0])
    if op1 == 1:
        str = str[::-1]
    else:
        op2 = int(line[1])
        char = line[2]
        if op2 == 1:
            str = char + str
        else:
            str += char
print(str)


Fixed submission:
"""
    Author: _YL_
"""
s = input()
n = int(input())

flip = 0
left = 0
right = 1
strs = ["", ""]

i = 0
while i < n:
    lst = input().split()

    if lst[0] == "1":
        flip += 1
        left = 0 if left == 1 else 1
        right = 0 if right == 1 else 1
    elif lst[1] == "1":
        strs[left] += lst[2]
    else:
        strs[right] += lst[2]
    i += 1

if flip % 2 == 1:
    s = s[::-1]
    
s = strs[left][::-1] + s + strs[right]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
"""
    Author: _YL_
"""
s = input()
n = int(input())

i = 0
while i < n:
    lst = input().split()

    if lst[0] == "1":
        temp = ""
        for letter in s:
            temp = letter + temp
        s = temp
    elif lst[1] == "1":
        s = lst[2] + s
    else:
        s += lst[2]

    i += 1

print(s)


Fixed submission:
"""
    Author: _YL_
"""
s = input()
n = int(input())

flip = 0
left = 0
right = 1
strs = ["", ""]

i = 0
while i < n:
    lst = input().split()

    if lst[0] == "1":
        flip += 1
        left = 0 if left == 1 else 1
        right = 0 if right == 1 else 1
    elif lst[1] == "1":
        strs[left] += lst[2]
    else:
        strs[right] += lst[2]
    i += 1

if flip % 2 == 1:
    s = s[::-1]
    
s = strs[left][::-1] + s + strs[right]

print(s)