Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input2 = sys.stdin.readline()

s=list(input2)
Q=int(input())

d=deque(s)
d.pop()
cnt=0
for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        cnt+=1
    else:
        if tmp[2] == "1":
            if (cnt > 0) and (cnt%2 == 0):
                d.appendleft(tmp[4])
                cnt=0
            elif cnt > 0:
                d.reverse()
                d.appendleft(tmp[4])
                cnt=0
            else:
                d.appendleft(tmp[4])
        else:
            if (cnt > 0) and (cnt%2 == 0):
                d.append(tmp[4])
                cnt=0
            elif cnt > 0:
                d.reverse()
                d.append(tmp[4])
                cnt=0
            else:
                d.append(tmp[4])
if (cnt > 0) and (cnt%2 != 0):
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)

Fixed submission:
from collections import deque
import sys
input2 = sys.stdin.readline()

s=list(input2)
Q=int(input())
direction=0
d=deque(s)
d.pop()

for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        if direction == 0:
            direction = 1
        else:
            direction = 0
    else:
        if tmp[2] == "1":
            if direction == 0:
                d.appendleft(tmp[4])
            else:
                d.append(tmp[4])
        else:
            if direction == 0:
                d.append(tmp[4])
            else:
                d.appendleft(tmp[4])
if direction==1:
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=list(input())
Q=int(input())

d=deque(s)
cnt=0
for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        cnt+=1
    else:
        if tmp[2] == "1":
            if (cnt > 0) and (cnt%2 == 0):
                d.appendleft(tmp[4])
                cnt=0
            elif cnt > 0:
                d.reverse()
                d.appendleft(tmp[4])
                cnt=0
            else:
                d.appendleft(tmp[4])
        else:
            if (cnt > 0) and (cnt%2 == 0):
                d.append(tmp[4])
                cnt=0
            elif cnt > 0:
                d.reverse()
                d.append(tmp[4])
                cnt=0
            else:
                d.append(tmp[4])
if (cnt > 0) and (cnt%2 != 0):
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)

Fixed submission:
from collections import deque
import sys
input2 = sys.stdin.readline()

s=list(input2)
Q=int(input())
direction=0
d=deque(s)
d.pop()

for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        if direction == 0:
            direction = 1
        else:
            direction = 0
    else:
        if tmp[2] == "1":
            if direction == 0:
                d.appendleft(tmp[4])
            else:
                d.append(tmp[4])
        else:
            if direction == 0:
                d.append(tmp[4])
            else:
                d.appendleft(tmp[4])
if direction==1:
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=list(input())
Q=int(input())

d=deque(s)
cnt=0
for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        cnt+=1
    else:
        if tmp[2] == "1":
            if (cnt > 0) and (cnt%2 == 0):
                d.appendleft(tmp[4])
                cnt=0
            elif cnt > 0:
                d.reverse()
                d.appendleft(tmp[4])
                cnt=0
            else:
                d.appendleft(tmp[4])
        else:
            if (cnt > 0) and (cnt%2 == 0):
                d.append(tmp[4])
                cnt=0
            elif cnt > 0:
                d.reverse()
                d.append(tmp[4])
                cnt=0
            else:
                d.append(tmp[4])
if (cnt > 0) and (cnt%2 != 0):
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)

Fixed submission:
from collections import deque
import sys
input2 = sys.stdin.readline()

s=list(input2)
Q=int(input())
direction=0
d=deque(s)
d.pop()

for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        if direction == 0:
            direction = 1
        else:
            direction = 0
    else:
        if tmp[2] == "1":
            if direction == 0:
                d.appendleft(tmp[4])
            else:
                d.append(tmp[4])
        else:
            if direction == 0:
                d.append(tmp[4])
            else:
                d.appendleft(tmp[4])
if direction==1:
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=list(input())
Q=int(input())

d=deque(s)

for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        d.reverse()
    else:
        if tmp[2] == "1":
            d.appendleft(tmp[4])
        else:
            d.append(tmp[4])
ans=list(d)
answer="".join(ans)
print(answer)

Fixed submission:
from collections import deque
import sys
input2 = sys.stdin.readline()

s=list(input2)
Q=int(input())
direction=0
d=deque(s)
d.pop()

for i in range(Q):
    tmp=list(input())
    if tmp[0] == "1":
        if direction == 0:
            direction = 1
        else:
            direction = 0
    else:
        if tmp[2] == "1":
            if direction == 0:
                d.appendleft(tmp[4])
            else:
                d.append(tmp[4])
        else:
            if direction == 0:
                d.append(tmp[4])
            else:
                d.appendleft(tmp[4])
if direction==1:
    d.reverse()
ans=list(d)
answer="".join(ans)
print(answer)