Buggy python submission (verdict: Time Limit Exceeded):
#input = raw_input

s = input()
q = int(input())

rev = False
for i in range(q):
    elms = input().split(" ")
    t = int(elms[0])
    if t == 1:
        rev = not rev
    else:
        f = int(elms[1])
        c = elms[2]

        if f == 1:
            if rev:
                s = s + c
            else:
                s = c + s
        else:
            if rev:
                s = c +s
            else:
                s = s + c
if rev:
    s = s[::-1]
print(s)

Fixed submission:
#input = raw_input

s = input()
q = int(input())

inputs = []
n_reverse = 0
for i in range(q):
    input_ = input()
    if input_[0] == "1":
        n_reverse += 1
    inputs.append(input_)

if n_reverse % 2 == 0:
    final_rev = False
else:
    final_rev = True

rev = False
mae = ""
ushiro = ""
for input_ in inputs:
    elms = input_.split(" ")
    t = int(elms[0])
    if elms[0] == "1":
        rev = not rev
    else:
        f = int(elms[1])
        c = elms[2]

        if f == 1:
            if final_rev:
                if rev:
                    mae = c + mae
                else:
                    ushiro = ushiro + c
            else:
                if rev:
                    ushiro = ushiro + c
                else:
                    mae = c + mae
        else:
            if final_rev:
                if rev:
                    ushiro = ushiro + c
                else:
                    mae = c + mae
            else:
                if rev:
                    mae = c + mae
                else:
                    ushiro = ushiro + c

if final_rev:
    s = s[::-1]

out = mae + s + ushiro
print(out)

Buggy python submission (verdict: Time Limit Exceeded):
input = raw_input

s = input()
q = int(input())

rev = False
for i in range(q):
    elms = input().split(" ")
    t = int(elms[0])
    if t == 1:
        rev = not rev
    else:
        f = int(elms[1])
        c = elms[2]

        if f == 1:
            if rev:
                s = s + c
            else:
                s = c + s
        else:
            if rev:
                s = c +s
            else:
                s = s + c
if rev:
    s = s[::-1]
print(s)

Fixed submission:
#input = raw_input

s = input()
q = int(input())

inputs = []
n_reverse = 0
for i in range(q):
    input_ = input()
    if input_[0] == "1":
        n_reverse += 1
    inputs.append(input_)

if n_reverse % 2 == 0:
    final_rev = False
else:
    final_rev = True

rev = False
mae = ""
ushiro = ""
for input_ in inputs:
    elms = input_.split(" ")
    t = int(elms[0])
    if elms[0] == "1":
        rev = not rev
    else:
        f = int(elms[1])
        c = elms[2]

        if f == 1:
            if final_rev:
                if rev:
                    mae = c + mae
                else:
                    ushiro = ushiro + c
            else:
                if rev:
                    ushiro = ushiro + c
                else:
                    mae = c + mae
        else:
            if final_rev:
                if rev:
                    ushiro = ushiro + c
                else:
                    mae = c + mae
            else:
                if rev:
                    mae = c + mae
                else:
                    ushiro = ushiro + c

if final_rev:
    s = s[::-1]

out = mae + s + ushiro
print(out)