#include <iostream>
#include <stack>
using namespace std;
int main()
{
int T;
cin >> T;
while(T--)
{
stack<long long> st;
int n;
cin >> n;
for(int i = 1; i <= n; i++)
{
string op;
cin >> op;
if(op == "push")
{
long long x;
cin >> x;
st.push(x);
}
else if(op == "pop")
{
if(st.empty()) cout << "Empty\n";
else st.pop();
}
else if(op == "query")
{
if(st.empty()) cout << "Anguei!\n";
else cout << st.top();
}
else cout << st.size() << endl;
}
}
return 0;
}