Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Fixed submission:
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
ans=""
ans+=S
for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            ans=query[2]+ans
        else:
            # deq.append(query[2])
            ans=ans+query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(ans)
else:
    print(ans[::-1])

Fixed submission:
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
ans=""
ans+=S
for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            ans=query[2]+ans
        else:
            # deq.append(query[2])
            ans=ans+query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(ans)
else:
    print(ans[::-1])

Fixed submission:
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
Q=int(input())

deq=deque()
for s in S:
    deq.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            deq.appendleft(query[2])
        else:
            deq.append(query[2])

if rev:
    deq.reverse()
ans=""
for i in range(len(deq)):
    ans+=deq[i]
print(ans)

Fixed submission:
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
Q=int(input())

ans=deque()
for s in S:
    ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])
    # print(ans)
if not rev:
    for i in range(len(ans)):
        print(ans[i],end="")
else:
    for i in range(len(ans)-1,-1,-1):
        print(ans[i],end="")

Fixed submission:
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Buggy python submission (verdict: Runtime Error):
from collections import deque
s=input()
Q=int(input())

ans=deque()
ans.append(s)
rev=False

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            ans.appendleft(query[2])
        else:
            ans.append(query[2])

if not rev:
    for si in ans:
        print(si,end="")
else:
    for i in range(len(ans),0,-1):
        print(ans[i],end="")

Fixed submission:
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])

Buggy python submission (verdict: Runtime Error):
s=[input()]
Q=int(input())

rev=-1
for i in range(Q):
    que=input().split()
    if que[0]=="1":
        rev*=-1
    else:
        if que[1]=="1":
            if rev>0:
                s.append(que[2])
            else:
                s=[que[2]]+s
        else:
            if rev<0:
                s.append(que[2])
            else:
                s=[que[2]]+s
if rev<0:
    for si in s:
        print(si,end="")
else:
    for i in range(len(s),0,-1):
        print(s[i],end="")

Fixed submission:
S=input()
Q=int(input())

# deq=deque()
# for s in S:
#     deq.append(s)

rev=False
front=""
last=""
# ans+=S

for _ in range(Q):
    query=input().split()
    if query[0]=="1":
        rev = not rev
        # print(rev)
    else:
        if rev:
            query[1]=str(3-int(query[1]))
        if query[1]=="1":
            # deq.appendleft(query[2])
            front=query[2]+front
        else:
            # deq.append(query[2])
            last+=query[2]

# if rev:
#     deq.reverse()
# # ans=""
# for i in range(len(deq)):
#     ans+=deq[i]

if not rev:
    print(front+S+last)
else:
    print(last[::-1]+S[::-1]+front[::-1])