Buggy python submission (verdict: Time Limit Exceeded):
import sys
s = sys.stdin.readline()
s = s[:-1]
q = int(input())

rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = ~rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            s = s + ci
        else:
            s = ci + s

if rv:
    s = s[::-1]
print(s)

Fixed submission:
import sys
s = sys.stdin.readline()
s = s[:-1]
q = int(input())

front = ''
back = ''
rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = not rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            back += ci
        else:
            front += ci

if rv:
    s = back[::-1] + s[::-1] + front
else:
    s = front[::-1] + s + back
print(s)

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

rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = ~rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            s.append(ci)
        else:
            s.insert(0, ci)

if rv:
    for i in range(1, len(s)+1):
        print(s[-i], end='')
    print('')
else:
    for si in s:
        print(si, end='')
    print('')

Fixed submission:
import sys
s = sys.stdin.readline()
s = s[:-1]
q = int(input())

front = ''
back = ''
rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = not rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            back += ci
        else:
            front += ci

if rv:
    s = back[::-1] + s[::-1] + front
else:
    s = front[::-1] + s + back
print(s)

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

rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = ~rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            s = s + ci
        else:
            s = ci + s
if rv:
    for i in range(1, len(s)+1):
        print(s[-i], end='')
    print('')
else:
    print(s)

Fixed submission:
import sys
s = sys.stdin.readline()
s = s[:-1]
q = int(input())

front = ''
back = ''
rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = not rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            back += ci
        else:
            front += ci

if rv:
    s = back[::-1] + s[::-1] + front
else:
    s = front[::-1] + s + back
print(s)

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

rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = ~rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            s = s + ci
        else:
            s = ci + s
if rv:
    for i in range(1, len(s)+1):
        print(s[-i], end='')
    print('')
else:
    print(s)

Fixed submission:
import sys
s = sys.stdin.readline()
s = s[:-1]
q = int(input())

front = ''
back = ''
rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = not rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            back += ci
        else:
            front += ci

if rv:
    s = back[::-1] + s[::-1] + front
else:
    s = front[::-1] + s + back
print(s)

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

rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = ~rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            s = s + ci
        else:
            s = ci + s
if rv:
    print(s[::-1])
else:
    print(s)

Fixed submission:
import sys
s = sys.stdin.readline()
s = s[:-1]
q = int(input())

front = ''
back = ''
rv = False
for i in range(q):
    line = input()
    if line[0] == '1':
        rv = not rv
    else:
        ti, fi, ci = line.split()
        if (fi == '1' and rv) or (fi == '2' and not rv):
            back += ci
        else:
            front += ci

if rv:
    s = back[::-1] + s[::-1] + front
else:
    s = front[::-1] + s + back
print(s)