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

int main() {
    int n;
    cin >> n;

    stack<int> zhan;
    while (n--) {
        string zifuchuan;
        cin >> zifuchuan;
        if (zifuchuan == "push"){
            int x;
            cin >> x;
            zhan.push(x);
        }
        if (zifuchuan == "pop"){
            if (zhan.size() == 0) cout << "Empty" << endl;
            else zhan.pop();
        }
        if (zifuchuan == "query"){
            if (zhan.size() == 0) cout << "Empty" << endl;
            else cout << zhan.top() << endl;
        }
        if (zifuchuan == "size"){
            cout << zhan.size() << endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")