#include<stdio.h>
#include<string.h>
#define MAX 100
int stack[MAX];
int top=-1;
void push(int x){
    if(top<MAX-1){
        stack[++top]=x;
    }
}
void pop(){
    if(top==-1){
        printf("Underflow");
    }
    else{
        top--;
    }
}
void peek(){
    if(top==-1){
        printf("Underflow");
        return;
    }
    else{
        printf("%d\n",stack[top]);
    }
    
}
void display(){
    if(top--){
        printf("\n");
        return;
    }
    else{
    for(int i=0;i<=top;i++){
        printf("%d ",stack[i]);
    }
    printf("\n");
}
}
int main(){
    int n;
    scanf("%d\n",&n);
     char cmd[20];
    for(int i=0;i<n;i++){
        fgets(cmd,sizeof(cmd),stdin
        cmd[strcspn(cmd,"\n")]=0;
        if(strncmp(cmd,"PUSH",4)==0){
            int x;
            sscanf(cmd+5,"%d",&x);
            push(x);
        }
        else if(strncmp(cmd,"POP",3)==0){
            pop();
        }
        else if(strncmp(cmd,"PEEK",4)==0){
            peek();
        }
        else if(strncmp(cmd,"DISPLAY",7)==0){
            display();
        }
    }
    return 0;
}