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