n= 5
head=0
tail=4
que=['a' , 'b' ,'c' ,'d' ,'e' ]
while head!=tail:
if head%4==0:
print (que[head])
else:
tail=(tail+1)%n
que[tail]=que[head]
head= (head+1)%n