#include<iostream>
using namespace std;
const int N = 1e6 + 7;
int t, n;
string a[N], x;
int main(){
int q = 0;
scanf("%d", &t);
while(t--){
scanf("%d", &n);
while(n--){
cin >> x;
if(x[0] == 'q'){
if(q == 0)
printf("Anguei!\n");
else
cout << a[q] << "\n";
}
if(x[0] == 's')
printf("%d\n", q);
if(x[0] == 'p'){
if(x[1] == 'o'){
if(q == 0)
printf("Empty\n");
else
q--;
}
else
cin >> a[++q];
}
}
}
return 0;
}