#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
using namespace std;

template <class T>
class Stack {
  public:
    Stack() {
        _data = (T*)malloc(4 * sizeof(T));
        _top = 0;
        _capacity = 4;
    }

    ~Stack() {
        free(_data);
        _top = _capacity = 0;
    }

    void push(T x) {
        if (_top == _capacity) {
            _capacity *= 2;
            _data = (T*)realloc(_data, _capacity * sizeof(T));
        }

        _data[_top++] = x;
    }

    void pop() {
        _top--;
    }

    T query() {
        return _data[_top - 1];
    }

    size_t size() {
        return _top;
    }

  private:
    T* _data;
    size_t _top;
    size_t _capacity;
};

int main() {
    int n, x;
    cin >> n;
    string s;
    Stack<int> st;

    while (n--) {
        cin >> s;

        if (s == "push") {
            cin >> x;
            st.push(x);
        } else if (s == "pop") {
            if (st.size() == 0) {
                cout << "Empty" << endl;
            } else {
                st.pop();
            }
        } else if (s == "query") {
            if (st.size() == 0) {
                cout << "Empty" << endl;
            } else {
                cout << st.query() << endl;
                // cout << st.top() << endl;
            }
        } else if (s == "size") {
            cout << st.size() << endl;
        }
    }

    return 0;
}