#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_LEN 100

// Node structure for linked list
struct Node {
    char name[MAX_LEN];
    struct Node *next;
};

// Function to check if the name has only alphabets
int isValidName(char *name) {
    for (int i = 0; name[i] != '\0'; i++) {
        if (!isalpha(name[i])) {
            return 0; // invalid
        }
    }
    return 1;
}

int main() {
    int n;
    scanf("%d", &n);

    if (n <= 1 || n > 1000) {
        printf("Invalid input\n");
        return 0;
    }

    struct Node *head = NULL, *tail = NULL;

    for (int i = 0; i < n; i++) {
        char temp[MAX_LEN];
        scanf("%s", temp);

        if (!isValidName(temp)) {
            printf("Invalid input\n");
            // Free allocated memory before exit
            struct Node *curr = head;
            while (curr) {
                struct Node *next = curr->next;
                free(curr);
                curr = next;
            }
            return 0;
        }

        // Create new node
        struct Node newNode = (struct Node)malloc(sizeof(struct Node));
        strcpy(newNode->name, temp);
        newNode->next = NULL;

        if (head == NULL) {
            head = tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }

    // Print the names in order
    struct Node *curr = head;
    while (curr) {
        printf("%s", curr->name);
        if (curr->next) printf(" ");
        curr = curr->next;
    }
    printf("\n");

    // Free allocated memory
    curr = head;
    while (curr) {
        struct Node *next = curr->next;
        free(curr);
        curr = next;
    }

    return 0;
}