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

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