#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SIZE 100 

// Define the Queue structure
typedef struct {
    char packets[MAX_SIZE][20]; // Assuming packet codes are strings
    int front;
    int rear;
    int size;
} Queue;

// Function to initialize the queue
void initQueue(Queue *q) {
    q->front = 0;
    q->rear = -1;
    q->size = 0;
}
// Function to check if the queue is empty
int isEmpty(Queue *q) {
    return q->size == 0;
}

// Function to add an element to the queue (enqueue)
void enqueue(Queue *q, const char *packetCode) {
    if (q->size == MAX_SIZE) {
        // This case should ideally not happen based on problem constraints (MAX_SIZE 100 events)
        // but for robustness, we can print an error or handle it.
        return;
    }
    q->rear = (q->rear + 1) % MAX_SIZE;
    strcpy(q->packets[q->rear], packetCode);
    q->size++;
}

// Function to remove an element from the queue (dequeue)
char* dequeue(Queue *q) {
    if (isEmpty(q)) {
        return NULL; // Queue is empty
    }
    char* packet = q->packets[q->front];
    q->front = (q->front + 1) % MAX_SIZE;
    q->size--;
    return packet;
}
int main() {
    Queue packetQueue;
    initQueue(&packetQueue);

    int numEvents;
    scanf("%d", &numEvents); // Read number of events

    if (numEvents < 1 || numEvents > 100) {
        printf("Invalid input\n");
        return 1;
    }

    for (int i = 0; i < numEvents; i++) {
        char eventType[20]; // To store 'packet_code' or 'signal'
        scanf("%s", eventType);

        if (strcmp(eventType, "signal") == 0) {
            if (isEmpty(&packetQueue)) {
                printf("line was empty\n");
            } else {
                char* sentPacket = dequeue(&packetQueue);
                printf("%s\n", sentPacket);
            }
        } else { // Assume it's a packet code if not "signal"
            // Validate packet code: only letters and digits, no spaces
            int isValidPacket = 1;
            for (int j = 0; j < strlen(eventType); j++) {
                if (!isalnum(eventType[j])) { // isalnum checks for alphanumeric
                    isValidPacket = 0;
                    break;
                }
            }

            if (isValidPacket) {
                enqueue(&packetQueue, eventType);
            } else {
                printf("Invalid input\n");
                // Optionally, you might want to exit or skip this event
            }
        }
    }

    return 0;
}