// editor5#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MAX 100
#define NAME_LEN 50

// Queue structure
typedef struct {
    char names[MAX][NAME_LEN];
    int front;
    int rear;
    int count;
} Queue;

void initQueue(Queue *q) {
    q->front = 0;
    q->rear = -1;
    q->count = 0;
}

int isEmpty(Queue *q) {
    return q->count == 0;
}

int isFull(Queue *q) {
    return q->count == MAX;
}

void enqueue(Queue *q, char *name) {
    if (!isFull(q)) {
        q->rear = (q->rear + 1) % MAX;
        strcpy(q->names[q->rear], name);
        q->count++;
    }
}

char* dequeue(Queue *q) {
    if (!isEmpty(q)) {
        char *name = q->names[q->front];
        q->front = (q->front + 1) % MAX;
        q->count--;
        return name;
    }
    return NULL;
}

int isValidName(char *name) {
    for (int i = 0; i < strlen(name); i++) {
        if (!isalpha(name[i])) return 0;
    }
    return 1;
}

int main() {
    int n;
    scanf("%d", &n);

    Queue q;
    initQueue(&q);

    char input[NAME_LEN];

    for (int i = 0; i < n; i++) {
        scanf("%s", input);

        if (strcmp(input, "LEAVE") == 0) {
            if (isEmpty(&q)) {
                printf("Line is empty\n");
            } else {
                char *person = dequeue(&q);
                printf("%s's turn\n", person);
            }
        } else {
            if (!isValidName(input)) {
                printf("Invalid input\n");
                return 0;
            }
            enqueue(&q, input);
        }
    }

return 0;
}