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

tcount = 0
rlist = ""
llist = ""

for i in range(q):
    qret = input()
    if qret[0] == "1":
        tcount += 1
    else:
        f = qret[2]
        c = qret[4]
        if f == "1":
            if tcount % 2 == 0:
                llist = c + llist
            else:
                rlist += c
        else:
            if tcount % 2 == 0:
                rlist += c
            else:
                llist = c + llist

if tcount % 2 == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])

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

tcount = 0
rlist = ""
llist = ""

for i in range(q):
    qret = input()
    if qret[0] == "1":
        tcount += 1
        # ans = ans[::-1]
    else:
        f = qret[2]
        c = qret[4]
        if f == "1":
            if tcount % 2 == 0:
                llist = c + llist
            else:
                rlist += c
        else:
            if tcount % 2 == 0:
                rlist += c
            else:
                llist = c + llist

if tcount % 2 == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])

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

ans = s
ret = "-1"

tcount = 0
rlist = ""
llist = ""

for i in range(q):
    qret = list(input().split())
    if qret[0] == "1":
        tcount += 1
        # ans = ans[::-1]
    else:
        f = qret[1]
        c = qret[2]
        if f == "1":
            if tcount % 2 == 0:
                llist += c
            else:
                rlist += c
        else:
            if tcount % 2 == 0:
                rlist += c
            else:
                llist += c

if tcount % 2 == 0:
    print(llist[::-1]+ans+rlist)
else:
    print(rlist[::-1]+ans[::-1]+llist)


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

tcount = 0
rlist = ""
llist = ""

for i in range(q):
    qret = input()
    if qret[0] == "1":
        tcount += 1
        # ans = ans[::-1]
    else:
        f = qret[2]
        c = qret[4]
        if f == "1":
            if tcount % 2 == 0:
                llist = c + llist
            else:
                rlist += c
        else:
            if tcount % 2 == 0:
                rlist += c
            else:
                llist = c + llist

if tcount % 2 == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])

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

ans = s
for i in range(q):
    qret = list(input().split())
    if qret[0] == "1":
        ans = ans[::-1]
    else:
        f = qret[1]
        c = qret[2]
        if f == "1":
            ans = c + ans
        else:
            ans += c

print(ans)


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

tcount = 0
rlist = ""
llist = ""

for i in range(q):
    qret = input()
    if qret[0] == "1":
        tcount += 1
        # ans = ans[::-1]
    else:
        f = qret[2]
        c = qret[4]
        if f == "1":
            if tcount % 2 == 0:
                llist = c + llist
            else:
                rlist += c
        else:
            if tcount % 2 == 0:
                rlist += c
            else:
                llist = c + llist

if tcount % 2 == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])

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

ans = s
for i in range(q):
    qret = list(input().split())
    if qret[0] == "1":
        ans.reverse()
    else:
        f = qret[1]
        c = qret[2]
        if f == "1":
            ans.insert(0, c)
        else:
            ans.append(c)

print(''.join(ans))


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

tcount = 0
rlist = ""
llist = ""

for i in range(q):
    qret = input()
    if qret[0] == "1":
        tcount += 1
        # ans = ans[::-1]
    else:
        f = qret[2]
        c = qret[4]
        if f == "1":
            if tcount % 2 == 0:
                llist = c + llist
            else:
                rlist += c
        else:
            if tcount % 2 == 0:
                rlist += c
            else:
                llist = c + llist

if tcount % 2 == 0:
    print(llist + s + rlist)
else:
    print(rlist[::-1] + s[::-1] + llist[::-1])