#include<bits/stdc++.h>
using namespace std;
const int N=1000001;
long long stl[N],tt=0,T,n,x;
int main(){
cin>>T;
while(T--){
memset(stl,0,sizeof(stl));
tt=0;
cin>>n;
while(n--){
string op;
cin>>op;
if(op=="push"){
cin>>x;
stl[++tt]=x;
}
else if(op=="pop"){
if(tt>0)tt--;
else cout<<"Empty"<<endl;
}
else if(op=="query"){
if(tt>0)cout<<stl[tt]<<endl;
else cout<<"Amguei!"<<endl;
}
else{
cout<<tt<<endl;
}
}
}
}