// editor5
 #include<stdio.h>
#include<string.h>
#include "postNode"
int main(){
    int N;
    scanf("%d", &N);
    getchar();
    char posts[100][100];
    int postCount = 0;
    for(int i = 0; i < N; i++){
        char command[20];
        scanf("%s", command);
        if(strcmp(command, "ADD") == 0){
            getchar();
            char text[100];
            fgets(text,sizeof(text),stdin);
            text[strcspn(text, "\n")] = '\0';
            if(strlen(text) == 0) continue;
            for(int j = postCount; j > 0; j--)
            strcpy(posts[j], posts[j - 1]);
            strcpy(posts[0], text);
            postCount++;
        }
        else if (strcmp(command, "DELETE") == 0){
            int index;
            scanf("%d", &index);
            if(index < 0 || index >= postCount){
                printf("Invalid input\n");
                continue;
            }
            for(int j = index; j < postCount - 1; j++)
            strcpy(posts[j], posts[j + 1]);
            postCount--;
        }
        else if(strcmp(command, "RETRIEVE") == 0){
            for(int j = 0; j < postCount; j++)
            printf("%s", posts[j]);
        }
        else{
            printf("Invalid input\n");
        }
    }
    return 0;

}