#include<stdio.h>
#include<string.h>
#define M 100

int q[M], f=-1, r=-1,n;

int empty(){ return  f==-1;}
int full(){return (f==0 && r==n-1) || f==r+1;}

void insF(int x){
    if(full()) return ;
    if(empty()) f=r=0;
    else f=(f==0)?n-1:f-1;
    q[f]=x;
}
void insR(int x){
    if(full())return ;
    if(empty()) f=r=0;
    else r(r==n-1)?0:r+1;
    q[r]=x;
}
void delF(){
    if (empty()) return ;
    printf("%d\n",q[f]);
    if(f==r) f=r=-1;
    else f=(f==n-1)?0:f+1;
}
void delF(){
    if (empty()) return ;
    printf("%d\n",q[r]);
    if(f==r) f=r=-1;
    else r=(r==0)?n-1:f+1;
}
int main(){
    char op[15];int x;
    scanf("%d",&n);
    while(scanf("%s",op)!=EOP){
        if(!struct(op,"insertFront")) scanf("%d",&x),insF(x);
        else if(!struct(op,"insertLast"))scanf("%d",&x),insF(x);
        else if(!struct(op,"deleteFront")) delF();
        else if(!struct(op,"deleteLast")) delR();
        else if(!struct(op,"getFront")&&!empty()) printf("%d\n",q[f]);
        else if(!struct(op,"getLast")&&!empty()) printf("%d\n",q[f]);
        else if(!struct(op,"isEmpty"))printf(empty()?"true\n":"flase\n");
        else if(!struct(op,"isFull"))printf(empty()?"true\n":"flase\n");
    }
}