#include<iostream>
#include<cstring>
using namespace std;
int main()
{
string str;
int a,b;
cin>>a;
for(int i=1;i<=a;i++)
{
cin>>b;
unsigned long long int stk[100010];
int top=0;
for(int j=1;j<=b;j++)
{
cin>>str;
if (str == "push")
{
int x;
cin >> x;
stk[++top]=x;
}
else if (str == "pop")
{
if (top==0)
cout << "Empty\n";
else
top--;
}
else if (str == "query")
{
if (top==0)
cout << "Anguei!\n";
else
cout<<stk[top]<<endl;
}
else
{
cout<<top<<endl;
}
}
}
}