// editor1
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define CAP 5

static void rtrim(char *s) {
    int i = (int)strlen(s) - 1;
    while (i >= 0 && (s[i] == '\n' || s[i] == '\r' || isspace((unsigned char)s[i]))) s[i--] = '\0';
}
static char* lskip(char *s) {
    while (*s && isspace((unsigned char)*s)) s++;
    return s;
}

int main(void) {
    int n;
    if (scanf("%d", &n) != 1) { puts("Invalid input"); return 0; }
    int c; while ((c = getchar()) != '\n' && c != EOF) {} // consume rest of line

    int stack[CAP];
    int top = -1;

    char line[256];
    for (int i = 0; i < n; ++i) {
        if (!fgets(line, sizeof line, stdin)) { puts("Invalid input"); return 0; }
        rtrim(line);
        char *p = lskip(line);

        if (strncmp(p, "peek",