Buggy python submission (verdict: Time Limit Exceeded):
S = input('')
Q = int(input(''))
rev_flag = 1
for i in range(Q):
    str = input('')
    if(str.count(' ') == 0 and str == '1'):
        rev_flag = -rev_flag
    elif(str[0] == '2' and ((str[2] == '1' and rev_flag == 1) or (str[2] == '2' and rev_flag == -1))):
        S = str[4] + S
    elif(str[0] == '2' and ((str[2] == '2' and rev_flag == 1) or (str[2] == '1' and rev_flag == -1))):
        S = S + str[4]
if rev_flag == 1:
    print(S)
elif rev_flag == -1:
    print(S[::-1])


Fixed submission:
S = input('')
Q = int(input(''))
head, tail, rev_flag = '', '', 1
for i in range(Q):
    char = input()
    if char == '1':
        rev_flag *= -1
    else:
        t, f, c = char.split()
        if (f == '1' and rev_flag == 1) or (f == '2' and rev_flag == -1):
            head = c + head
        elif (f == '2' and rev_flag == 1) or (f == '1' and rev_flag == -1):
            tail = tail + c
if rev_flag == 1:
    print(head, S, tail, sep='')
else:
    print(tail[::-1], S[::-1], head[::-1], sep='')

Buggy python submission (verdict: Runtime Error):
S = input('')
Q = int(input(''))
rev_flag = 1
for i in range(Q):
    str = input('')
    if(str.count(' ') == 0 and str == '1'):
        rev_flag = -rev_flags
    elif(str[0] == '2' and ((str[2] == '1' and rev_flag == 1) or (str[2] == '2' and rev_flag == -1))):
        S = str[4] + S
    elif(str[0] == '2' and ((str[2] == '2' and rev_flag == 1) or (str[2] == '1' and rev_flag == -1))):
        S = S + str[4]
if rev_flag == 1:
    print(S)
elif rev_flag == -1:
    print(S[::-1])


Fixed submission:
S = input('')
Q = int(input(''))
head, tail, rev_flag = '', '', 1
for i in range(Q):
    char = input()
    if char == '1':
        rev_flag *= -1
    else:
        t, f, c = char.split()
        if (f == '1' and rev_flag == 1) or (f == '2' and rev_flag == -1):
            head = c + head
        elif (f == '2' and rev_flag == 1) or (f == '1' and rev_flag == -1):
            tail = tail + c
if rev_flag == 1:
    print(head, S, tail, sep='')
else:
    print(tail[::-1], S[::-1], head[::-1], sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S = input('')
Q = int(input(''))
for i in range(Q):
    str = input('')
    if(str.count(' ') == 0 and str == '1'):
        S = S[::-1]
    elif(str[0] == '2' and str[2] == '1'):
        S = '{0}{1}'.format(str[4], S)
    elif(str[0] == '2' and str[2] == '2'):
        S = '{0}{1}'.format(S, str[4])
print(S)

Fixed submission:
S = input('')
Q = int(input(''))
head, tail, rev_flag = '', '', 1
for i in range(Q):
    char = input()
    if char == '1':
        rev_flag *= -1
    else:
        t, f, c = char.split()
        if (f == '1' and rev_flag == 1) or (f == '2' and rev_flag == -1):
            head = c + head
        elif (f == '2' and rev_flag == 1) or (f == '1' and rev_flag == -1):
            tail = tail + c
if rev_flag == 1:
    print(head, S, tail, sep='')
else:
    print(tail[::-1], S[::-1], head[::-1], sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S = input('')
Q = int(input(''))
for i in range(Q):
    str = input('')
    if(str.count(' ') == 0 and str == '1'):
        S = S[::-1]
    else:
        if(str[0] == '2' and str[2] == '1'):
            S = '{0}{1}'.format(str[4], S)
        elif(str[0] == '2' and str[2] == '2'):
            S = '{0}{1}'.format(S, str[4])
print(S)

Fixed submission:
S = input('')
Q = int(input(''))
head, tail, rev_flag = '', '', 1
for i in range(Q):
    char = input()
    if char == '1':
        rev_flag *= -1
    else:
        t, f, c = char.split()
        if (f == '1' and rev_flag == 1) or (f == '2' and rev_flag == -1):
            head = c + head
        elif (f == '2' and rev_flag == 1) or (f == '1' and rev_flag == -1):
            tail = tail + c
if rev_flag == 1:
    print(head, S, tail, sep='')
else:
    print(tail[::-1], S[::-1], head[::-1], sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S = input('')
Q = int(input(''))
for i in range(Q):
    str = input('')
    if(str.count(' ') == 0 and str == '1'):
        S = S[::-1]
    else:
        T, F, C = str.split(' ')
        if(T == '2' and F == '1'):
            S = C + S
        elif(T == '2' and F == '2'):
            S = S + C
print(S)


Fixed submission:
S = input('')
Q = int(input(''))
head, tail, rev_flag = '', '', 1
for i in range(Q):
    char = input()
    if char == '1':
        rev_flag *= -1
    else:
        t, f, c = char.split()
        if (f == '1' and rev_flag == 1) or (f == '2' and rev_flag == -1):
            head = c + head
        elif (f == '2' and rev_flag == 1) or (f == '1' and rev_flag == -1):
            tail = tail + c
if rev_flag == 1:
    print(head, S, tail, sep='')
else:
    print(tail[::-1], S[::-1], head[::-1], sep='')