#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

typedef struct LNode {
    int data;
    struct LNode* next;
} LNode, *LinkStack ;

// 初始化一个链栈
bool Init(LinkStack& S) {
    // 创建一个头结点
    S = (LNode*)malloc(sizeof(LNode));
    // 分配空间失败
    if (S == NULL) return false;
    // 让头结点指向NULL
    S->next = NULL;
    return true;
}

// 入栈
bool Push(LinkStack& S, int x) {
    // S是非法栈
    if (S == NULL) return false;
    // 创建一个数据节点
    LNode* n = (LNode*)malloc(sizeof(LNode));
    n->data = x;
    // 数据结点指后段链表
    n->next = S->next;
    // 头结点指向数据结点
    S->next = n;
    return true;
}

// 出栈
bool Pop(LinkStack& S, int& x) {
    // 判断栈空
    if (S->next == NULL) return false;
    // 临时指针指向要释放的结点
    LNode* p = S->next;
    // 头结点指向新的第一数据结点
    S->next = p->next;
    // 存数据,销毁结点
    x = p->data;
    free(p);
    return true;
}

// 查栈顶
bool GetTop(LinkStack& S, int& x) {
    // 判断是否有栈顶元素
    if (S->next == NULL)return false;
    x = S->next->data;
    return true;
}
int main() {
    LinkStack S;
    Init(S);
    std::string a, b;
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string op;
        cin >> op;
        if (op == "push") {
            int  x;
            cin >> x;
            if (!Push(S, x)) {
                cout << "error" << endl;
            };
        }
        if (op == "pop") {
            int x;
            if (!Pop(S, x)) {
                cout << "error" << endl;
            } else
                cout << x << endl;


        }
        int y;
        if (op == "top") {
            if (!GetTop(S, y)) {
                cout << "error" << endl;

            } else
                cout << y << endl;
        }
    }
}