Buggy python submission (verdict: Time Limit Exceeded):
"""
D - String Formation
"""
s = input()
q = int(input())
string = []
is_normal = 1
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                s = emir[4] + s
            elif emir[2] == '2':
                s += emir[4]
        else:
            if emir[2] == '1':
                s += emir[4]
            elif emir[2] == '2':
                s = emir[4] + s
if is_normal == -1:
    s = s[::-1]

print(s)


Fixed submission:
s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
        else:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
s = sol[::-1] + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
"""
D - String Formation
"""
s = input()
q = int(input())
string = []
for i in range(q):
    string.append(input())
i = 0
while i < len(string):
    emir = string[i]
    if i+1 == len(string):
        if emir[0] == '1':
            s = s[::-1]
            i += 1
        elif emir[0] == '2':
            if emir[2] == '1':
                s = emir[4] + s
                i += 1
            elif emir[2] == '2':
                s += emir[4]
                i += 1
    else:
        sonraki = string[i+1]
        if emir[0] == sonraki[0] == '1':
            i = i + 2
        elif emir[0] == '1':
            s = s[::-1]
            i += 1
        elif emir[0] == '2':
            if emir[2] == '1':
                s = emir[4] + s
                i += 1
            elif emir[2] == '2':
                s += emir[4]
                i += 1
print(s)

Fixed submission:
s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
        else:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
s = sol[::-1] + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    emir = input()
    if emir[0] == '1':
        s = s[::-1]
    elif emir[0] == '2':
        if emir[2] == '1':
            s = emir[4] + s
        elif emir[2] == '2':
            s += emir[4]
print(s)

Fixed submission:
s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
        else:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
s = sol[::-1] + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    emir = input()
    if emir[0] == '1':
        s = s[::-1]
    elif emir[0] == '2':
        if emir[2] == '1':
            s = emir[4] + s
        elif emir[2] == '2':
            s += emir[4]
print(s)

Fixed submission:
s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
        else:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
s = sol[::-1] + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
string = []
for i in range(q):
    emir = input()
    if emir[0] == '1':
        s = s[::-1]
    if emir[0] == '2':
        if emir[2] == '1':
            s = emir[4] + s
        elif emir[2] == '2':
            s += emir[4]
print(s)

Fixed submission:
s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
        else:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
s = sol[::-1] + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
"""
D - String Formation
"""
s = input()
q = int(input())
string = []
for i in range(q):
    string.append(input())

for emir in string:
    if emir[0] == '1':
        s = s[::-1]
    if emir[0] == '2':
        if emir[2] == '1':
            s = emir[4] + s
        elif emir[2] == '2':
            s += emir[4]

print(s)

Fixed submission:
s = input()
q = int(input())
string = []
is_normal = 1
saq = ""
sol = ""
for i in range(q):
    emir = input()
    if emir[0] == '1':
        is_normal *= -1
    elif emir[0] == '2':
        if is_normal == 1:
            if emir[2] == '1':
                sol += emir[4]
            elif emir[2] == '2':
                saq += emir[4]
        else:
            if emir[2] == '1':
                saq += emir[4]
            elif emir[2] == '2':
                sol += emir[4]
s = sol[::-1] + s + saq
if is_normal == -1:
    s = s[::-1]

print(s)