Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    else:
        if cnt%2!=0:
            s.reverse()
        if int(que[1])==1:
            s=deque(s)
            s.appendleft(que[2])
            cnt=0
        elif int(que[1])==2:
            s=deque(s)
            s.append(que[2])
            cnt=0
if cnt%2!=0:
    s.reverse()
print(''.join(s)) 


Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(stdin.readline().rstrip())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    else:
        if cnt%2!=0:
            s.reverse()
        if int(que[1])==1:
            s=deque(s)
            s.appendleft(que[2])
            cnt=0
        elif int(que[1])==2:
            s=deque(s)
            s.append(que[2])
            cnt=0
if cnt%2!=0:
    s.reverse()
print(''.join(s)) 

Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    else:
        if cnt%2!=0:
            s.reverse()
        if int(que[1])==1:
            s=deque(s)
            s.appendleft(que[2])
            cnt=0
        elif int(que[1])==2:
            s=deque(s)
            s.append(que[2])
            cnt=0
if cnt%2!=0:
    s.reverse()
print(''.join(s)) 

Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        s.reverse()
    else:
        if int(que[1])==1:
            s=deque(s)
            s.appendleft(que[2])
        elif int(que[1])==2:
            s=deque(s)
            s.append(que[2])
print(''.join(s)) 

Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        s=list(s)
        s=s[::-1]
    else:
        if int(que[1])==1:
            s=deque(s)
            s.appendleft(que[2])
        elif int(que[1])==2:
            s=deque(s)
            s.append(que[2])
s=list(s)
print(''.join(s)) 

Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        s=list(s)
        s=s[::-1]
        s=deque(s)
    else:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
s=list(s)
print(''.join(s)) 

Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
q=int(input())
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        s=s[::-1]
    else:
        if int(que[1])==1:
            s=que[2]+s
        elif int(que[1])==2:
            s=s+que[2]
print(s) 

Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s=str(input())
q=int(input())
for i in range(q):
    que=list(input())
    if len(que)==1:
        s=s[::-1]
    else:
        if int(que[2])==1:
            s=que[4]+s
        elif int(que[2])==2:
            s=s+que[4]
print(s) 

Fixed submission:
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s))