#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX_SIZE 5

int stack[MAX_SIZE];
int top = -1;

void push(int x) {
    if (top >= MAX_SIZE - 1) {
        printf("Stack overflow\n");
    } else {
        stack[++top] = x;
    }
}

void peek() {
    if (top == -1) {
        printf("Stack is empty\n");
    } else {
        printf("%d\n", stack[top]);
    }
}

// Function to check if a string is a valid integer
int isInteger(char *str) {
    if (*str == '-' || *str == '+') str++; // allow sign
    if (*str == '\0') return 0; // sign alone is invalid
    while (*str) {
        if (!isdigit(*str)) return 0;
        str++;
    }
    return 1;
}

int main() {
    int n;
    if (scanf("%d", &n) != 1) {
        printf("Invalid input\n");
        return 0;
    }
    getchar(); // consume newline after number

    for (int i = 0; i < n; i++) {
        char line[100];
        if (fgets(line, sizeof(line), stdin) == NULL) {
            printf("Invalid input\n");
            continue;
        }

        // Remove trailing newline
        line[strcspn(line, "\n")] = 0;

        if (strncmp(