lst=[]
n,m=map(int,input().split())
for i in range(m):
s=input()
lst1=[x for x in s.split()]
if lst1[0]=='pushLeft' and len(lst)<n:
lst=[lst1[1]]+lst
print("Pushed in left: "+lst1[1])
elif lst1[0]=='pushRight' and len(lst)<n:
lst.append(lst1[1])
print("Pushed in right: "+lst1[1])
elif (lst1[0]=='pushLeft' or lst1[0]=='pushRight') and len(lst)==n:
print("The queue is full")
elif lst1[0]=='popLeft' and len(lst)>0:
t=lst.pop(0)
print('Popped from left: '+t)
elif lst1[0]=='popRight' and len(lst)>0:
t=lst.pop()
print('Popped from right: '+t)
elif (lst1[0]=='popLeft' or lst1[0]=='popRight') and len(lst)==0:
print('The queue is empty')