#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct Node {
    char name[101];
    struct Node* next;
};

int isValidName(char* str) {
    for (int i = 0; str[i]; i++) {
        if (!isalpha(str[i]) && str[i] != ' ') return 0;
    }
    return 1;
}

struct Node* createNode(char* name) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    strcpy(newNode->name, name);
    newNode->next = NULL;
    return newNode;
}

void insertTail(struct Node** tail, int* size, int limit, char* name) {
    struct Node* newNode = createNode(name);
    if (*tail == NULL) {
        newNode->next = newNode;
        *tail = newNode;
        *size = 1;
    } else {
        newNode->next = (*tail)->next;
        (*tail)->next = newNode;
        *tail = newNode;
        if (*size < limit) {
            (*size)++;
        } else {
            struct Node* temp = (*tail)->next;
            (*tail)->next = temp->next;
            free(temp);
        }
    }
}

void printLog(struct Node* tail) {
    if (tail == NULL) return;
    struct Node* temp = tail;
    do {