#include <stdio.h>
#include <string.h>
#include <ctype.h>

struct Node {
    char name[101];
    struct Node *next;
};

int isValidName(char *name) {
    for (int i = 0; name[i] != '\0'; i++) {
        if (!isalnum((unsigned char)name[i])) { 
            return 0;
        }
    }
    return 1;
}

int main() {
    int n;
    if (scanf("%d", &n) != 1) return 0;

    struct Node *head = NULL, *tail = NULL;

    for (int i = 0; i < n; i++) {
        char temp[101];
        scanf("%s", temp);

        if (!isValidName(temp)) {
            printf("Invalid input");
            return 0;
        }

        struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
        if (!newNode) return 0; // malloc failed
        strcpy(newNode->name, temp);
        newNode->next = NULL;

        if (head == NULL) {
            head = newNode;
            tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }

    int stopSignal;
    scanf("%d", &stopSignal);

    struct Node *curr = head;
    while (curr != NULL) {
        printf("%s", curr->name);
        curr = curr->next;
        if (curr != NULL) printf(" ");
    }

    // Free allocated memory
    while (head != NULL) {
        struct Node *temp = head;
        head = head->next;
        free(temp);
    }

    return 0;
}