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

const int N = 100010;

int main() {
    int stk[N], tt = 0;  // tt 指向栈顶元素的位置,0 表示空
    int n;
    cin >> n;

    while (n--) {
        string op;
        cin >> op;

        if (op == "push") {
            int x;
            cin >> x;
            stk[++tt] = x;  // 先移动 tt,再赋值
        } else if (op == "pop") {
            if (tt == 0) {
                cout << "Empty" << endl;
            } else {
                tt--;  // 逻辑删除
            }
        } else if (op == "query") {
            if (tt == 0) {
                cout << "Empty" << endl;
            } else {
                cout << stk[tt] << endl;
            }
        } else if (op == "size") {
            cout << tt << endl;
        }
    }

    return 0;
}