#include<bits/stdc++.h>
using namespace std;
stack <unsigned long long> s;
unsigned long long i, n, x, opt, T, len;
string st;
int main()
{
cin>>T;
while(T--)
{
cin>>n;
len=0;
for(i=1;i<=n;i++)
{
cin>>st;
if(st=="push")
{
cin>>x;
s.push(x);
len++;
}
if(st=="size")
{
cout<<len<<endl;
}
if(st=="pop")
{
if(s.empty())
{
cout<<"Empty"<<endl;
}
else {
s.pop();
}
}
if(st=="query")
{
if(s.empty())
{
cout<<"Anguei!"<<endl;
}
else {
cout<<s.top()<<endl;
}
}
}
while(!s.empty())
{
s.pop();
}
}
return 0;
}