#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

typedef struct Node {
    char data[101];
    struct Node* next;
} Node;

Node* createNode(char* str) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    if (!newNode) {
        printf("Memory allocation failed");
        exit(0);
    }
    strcpy(newNode->data, str);
    newNode->next = NULL;
    return newNode;
}

int isValid(char* str) {
    for (int i = 0; str[i]; i++) {
        if (!isalpha(str[i])) return 0; // only alphabets allowed
    }
    return 1;
}

void displayList(Node* head, int n) {
    if (head == NULL) return;
    Node* temp = head;
    for (int i = 0; i < n; i++) {
        printf("%s", temp->data);
        if (i != n - 1) printf(" ");
        temp = temp->next;
    }
}

int main() {
    int n;
    if (scanf("%d", &n) != 1 || n < 1 || n > 1000) {
        printf("Invalid input");
        return 0;
    }

    Node *head = NULL, *tail = NULL;
    char str[101];

    for (int i = 0; i < n; i++) {
        if (scanf("%s", str) != 1 || !isValid(str)) {
            printf("Invalid input");
            return 0;
        }

        Node* newNode = createNode(str);

        if (head == NULL) {
            head = newNode;
            tail = newNode;
            newNode->next = newNode; // circular
        } else {