Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    else:
        if (int(a[2]) + rev) % 2 == 1:
            s = "{}{}".format(a[4],s)
        else:
            s = "{}{}".format(s,a[4])
    
if rev%2 == 0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
s = input()
q = int(input())
rev = 0
mae = []
usiro = []

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    else:
        if (int(a[2]) + rev) % 2 == 1:
            mae.append(a[4])
        else:
            usiro.append(a[4])
            
mae = mae[::-1]
mae2 = "".join(mae)
usiro2 = "".join(usiro)
if rev%2 == 0:
    print(mae2 + s + usiro2)
else:
    ans = mae2 + s + usiro2
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    else:
        if (int(a[2]) + rev) % 2 == 1:
            s = a[4] + s
        else:
            s += a[4]
    
if rev%2 == 0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
s = input()
q = int(input())
rev = 0
mae = []
usiro = []

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    else:
        if (int(a[2]) + rev) % 2 == 1:
            mae.append(a[4])
        else:
            usiro.append(a[4])
            
mae = mae[::-1]
mae2 = "".join(mae)
usiro2 = "".join(usiro)
if rev%2 == 0:
    print(mae2 + s + usiro2)
else:
    ans = mae2 + s + usiro2
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0
mae = ""
usiro = ""

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    else:
        if (int(a[2]) + rev) % 2 == 1:
            mae += a[4]
        else:
            usiro += a[4]

mae = list(reversed(mae))
mae2 = "".join(mae)
s = mae2 + s + usiro
if rev%2 == 0:
    print(s)
else:
    s = list(reversed(s))
    ans = "".join(s)
    print(ans)

Fixed submission:
s = input()
q = int(input())
rev = 0
mae = []
usiro = []

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    else:
        if (int(a[2]) + rev) % 2 == 1:
            mae.append(a[4])
        else:
            usiro.append(a[4])
            
mae = mae[::-1]
mae2 = "".join(mae)
usiro2 = "".join(usiro)
if rev%2 == 0:
    print(mae2 + s + usiro2)
else:
    ans = mae2 + s + usiro2
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
rev = 0

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    if a[0] == '2':
        if (int(a[2]) + rev) % 2 == 1:
            s = a[4] + s
        else:
            s += a[4]
    
if rev%2 == 0:
    print(s)
else:
    s = list(reversed(s))
    ans = "".join(s)
    print(ans)

Fixed submission:
s = input()
q = int(input())
rev = 0
mae = []
usiro = []

for i in range(q):
    a = input()
    
    if a[0] == '1':
        rev += 1
    else:
        if (int(a[2]) + rev) % 2 == 1:
            mae.append(a[4])
        else:
            usiro.append(a[4])
            
mae = mae[::-1]
mae2 = "".join(mae)
usiro2 = "".join(usiro)
if rev%2 == 0:
    print(mae2 + s + usiro2)
else:
    ans = mae2 + s + usiro2
    print(ans[::-1])