#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], TOP = 0;
int push(int x){
a[++TOP] = x ;
++TOP;
}
void pop(){
--TOP;
}
void query(){
if (TOP >= 0){
cout<<a[TOP - 1];
}
if (TOP < 0){
cout<<"Anguei!";
}
}
void size(){
cout<<TOP;
}
int main(){
int T = 0 ;
cin>>T;
for (int i = 0 ; i < T ; ++i){
int n = 0 ;
cin>>n;
for (int j = 0 ; j < n ; ++j){
string s;
int w = 0 ;
cin>>s;
if (s == "push"){
cin>>w;
push(w);
}
if (s == "query"){
query();
}
if (s == "size"){
size();
}
if (s == "pop"){
pop();
}
}
}
return 0 ;
}