#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

// Node structure for doubly linked list
typedef struct Node {
    char* data;
    struct Node* next;
    struct Node* prev;
} Node;

// Function to add a node to the beginning of the doubly linked list
void addNode(Node** head, char* data) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    newNode->data = strdup(data);
    newNode->next = *head;
    newNode->prev = NULL;
    if (*head) {
        (*head)->prev = newNode;
    }
    *head = newNode;
}

// Function to print the doubly linked list
void printList(Node* head) {
    Node* current = head;
    while (current) {
        printf("%s ", current->data);
        current = current->next;
    }
    printf("\n");
}

// Function to check if a string contains digits
int containsDigits(const char* str) {
    for (int i = 0; str[i]; i++) {
        if (isdigit(str[i])) {
            return 1;
        }
    }
    return 0;
}

// Function to free the list
void freeList(Node* head) {
    Node* current = head;
    while (current) {
        Node* next = current->next;
        free(current->data);
        free(current);
        current = next;
    }
}

int main() {
    int n;
    if (scanf("%d", &n) != 1 || n < 0 || n > 1000) {
        printf("Invalid input\n");
        return 1;
    }
    getchar(); // Consume newline

    Node* head = NULL;
    char task[100];
    for (int i = 0; i < n; i++) {
        if (fgets(task, sizeof(task), stdin) == NULL) {
            printf("Invalid input\n");
            return 1;
        }
        task[strcspn(task, "\n")] = 0; // Remove newline
        addNode(&head, task);
    }

    char newTask[100];
    if (fgets(newTask, sizeof(newTask), stdin) == NULL) {
        printf("Invalid input\n");
        freeList(head);
        return 1;
    }
    newTask[strcspn(newTask, "\n")] = 0; // Remove newline

    if (containsDigits(newTask)) {
        printf("Invalid input\n");
    } else {
        addNode(&head, newTask);
        printList(head);
    }

    freeList(head);
    return 0;
}