Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
for i,q in enumerate(query):
  if len(q)==1:
    ans.reverse()
  else:
    _,f,c=q
    if f=='1':
      ans.appendleft(c)
    else:
      ans.append(c)
print(*ans,sep='')

Fixed submission:
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
for i,q in enumerate(query):
  if len(q)==1:
    tmp=''
    for a in ans:
      tmp+=a
    ans=deque(tmp[::-1])
  else:
    _,f,c=q
    if f=='1':
      ans.appendleft(c)
    else:
      ans.append(c)
print(*ans,sep='')

Fixed submission:
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=[]
for s in S:
  ans.append(s)
for q in query:
  if len(q)==1:
    ans=ans[::-1]
  else:
    _,f,c=q
    if f=='1':
      ans.insert(0,c)
    else:
      ans.append(c)
print(*ans,sep='')

Fixed submission:
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque()
for s in S:
  ans.append(s)
for i,q in enumerate(query):
  if len(q)==1:
    tmp=''
    for a in ans:
      tmp+=a
    ans=deque(tmp[::-1])
  else:
    _,f,c=q
    if f=='1':
      ans.appendleft(c)
    else:
      ans.append(c)
print(*ans,sep='')

Fixed submission:
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque()
for s in S:
  ans.append(s)
for q in query:
  if len(q)==1:
    ans.reverse()
  else:
    _,f,c=q
    if f=='1':
      ans.appendleft(c)
    else:
      ans.append(c)
print(*ans,sep='')

Fixed submission:
from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')