Buggy python submission (verdict: Runtime Error):
s  = input()
n  = int(input())

is_seiichi = True
s_head_append = ''

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        is_seiichi = not is_seiichi
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_seiichi ^ is_head:
            #s = s + s_
            s_head_append += s
        else:
            s = s_ + s_head_append + s
            s_head_append = ''

print(s + s_head_append if is_seiichi else s_head_append[::-1] + s[::-1])


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

s_mae = ''
s_ato = s

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s_mae, s_ato = s_ato, s_mae
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_head:
            s_mae += s_
        else:
            s_ato += s_

print(s_mae[::-1] + s_ato)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
s  = input()
n  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

is_seiichi = True

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        is_seiichi = not is_seiichi
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_seiichi ^ is_head:
            s = s + s_
        else:
            s = s_ + s

print(s if is_seiichi else s[::-1])


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

s_mae = ''
s_ato = s

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s_mae, s_ato = s_ato, s_mae
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_head:
            s_mae += s_
        else:
            s_ato += s_

print(s_mae[::-1] + s_ato)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
s  = input()
n  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

is_seiichi = True

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        is_seiichi = not is_seiichi
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_seiichi ^ is_head:
            s = s + s_
        else:
            s = s_ + s

print(s if is_seiichi else s[::-1])


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

s_mae = ''
s_ato = s

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s_mae, s_ato = s_ato, s_mae
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_head:
            s_mae += s_
        else:
            s_ato += s_

print(s_mae[::-1] + s_ato)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
s  = input()
n  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s = s[::-1]
    else:
        _, id_, s_ = ipt.split()
        if id_ == '1':
            s = s_ + s
        else:
            s = s + s_

print(s)


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

s_mae = ''
s_ato = s

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s_mae, s_ato = s_ato, s_mae
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_head:
            s_mae += s_
        else:
            s_ato += s_

print(s_mae[::-1] + s_ato)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
s  = input()
n  = int(input())
#  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s = s[::-1]
    else:
        _, id_, s_ = ipt.split()
        if id_ == '1':
            s = s_ + s
        else:
            s = s + s_

print(s)


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

s_mae = ''
s_ato = s

for _ in range(n):
    ipt = input()

    if ipt[0] == '1':
        s_mae, s_ato = s_ato, s_mae
    else:
        _, id_, s_ = ipt.split()
        is_head = True if id_ == '1' else False
        if is_head:
            s_mae += s_
        else:
            s_ato += s_

print(s_mae[::-1] + s_ato)