Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
            c = q_i[4] +c
    elif (q_i[2] =='2' and hantei == 1) or (q_i[2] == '1' and hantei == -1):
            c += q_i[4]

if hantei == -1:
    c = c[::-1]


print(c)


Fixed submission:
import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)
c_mae = ''
c_ato = ''

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
        c_mae = q_i[4] + c_mae
    else:
        c_ato += q_i[4]

print(c_mae+c+c_ato if hantei == 1 else (c_mae+c+c_ato)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)

hantei = 0

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1' and hantei ==0:
        hantei = 1
    elif q_i[0] == '1' and hantei == 1:
        hantei = 0
    elif (q_i[2] =='1' and hantei == 0) or (q_i[2] == '2' and hantei == 1):
            c = q_i[4] +c
    elif (q_i[2] =='2' and hantei == 0) or (q_i[2] == '1' and hantei ==1):
            c += q_i[4]



if hantei == 1:
    c = c[::-1]


print(c)


Fixed submission:
import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)
c_mae = ''
c_ato = ''

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
        c_mae = q_i[4] + c_mae
    else:
        c_ato += q_i[4]

print(c_mae+c+c_ato if hantei == 1 else (c_mae+c+c_ato)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

c = list(input())
c = c[:len(c)-1]
q = int(input())

num = len(c)

q_i =  [list(input()) for _ in range(q)]

#print(q_i)

hantei = 0

for i in range(q):
    #q_i= list(input())
    #print(q_i)
    if q_i[i][0] == '1' and hantei ==0:
        hantei = 1
    elif q_i[i][0] == '1' and hantei == 1:
        hantei = 0
    elif (q_i[i][2] =='1' and hantei == 0) or (q_i[i][2] == '2' and hantei == 1):
            c = [q_i[i][4]] +c
    elif (q_i[i][2] =='2' and hantei == 0) or (q_i[i][2] == '1' and hantei ==1):
            c += [q_i[i][4]]



if hantei == 0:
    ans = ''
    for i in range(len(c)):
        ans += c[i]
else:
    ans = ''
    for i in range(len(c)):
        ans = c[i] + ans


print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)
c_mae = ''
c_ato = ''

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
        c_mae = q_i[4] + c_mae
    else:
        c_ato += q_i[4]

print(c_mae+c+c_ato if hantei == 1 else (c_mae+c+c_ato)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

c = list(input())
c = c[:len(c)-1]
q = int(input())

num = len(c)

hantei = 0

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1' and hantei ==0:
        hantei = 1
    elif q_i[0] == '1' and hantei == 1:
        hantei = 0
    elif (q_i[2] =='1' and hantei == 0) or (q_i[2] == '2' and hantei == 1):
            c = [q_i[4]] +c
    elif (q_i[2] =='2' and hantei == 0) or (q_i[2] == '1' and hantei ==1):
            c += [q_i[4]]



if hantei == 0:
    ans = ''
    for i in range(len(c)):
        ans += c[i]
else:
    ans = ''
    for i in range(len(c)):
        ans = c[i] + ans


print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

c = input()
c = c[:len(c)-1]
q = int(input())

num = len(c)
c_mae = ''
c_ato = ''

hantei = 1

for i in range(q):
    q_i= list(input())
    #print(q_i)
    if q_i[0] == '1':
        hantei *= -1
    elif (q_i[2] =='1' and hantei == 1) or (q_i[2] == '2' and hantei == -1):
        c_mae = q_i[4] + c_mae
    else:
        c_ato += q_i[4]

print(c_mae+c+c_ato if hantei == 1 else (c_mae+c+c_ato)[::-1])