/*
* @Author: Aisaka_Taiga
* @Date: 2023-10-19 14:11:38
* @LastEditTime: 2023-10-19 14:33:54
* @LastEditors: Aisaka_Taiga
* @FilePath: \Desktop\B3614.cpp
* The heart is higher than the sky, and life is thinner than paper.
*/
#include <bits/stdc++.h>
#define int unsigned long long
#define N 1000100
using namespace std;
inline int read()
{
int x = 0, f = 1;
char c = getchar();
while(c < '0' || c > '9'){if(c == '-') f = -1; c = getchar();}
while(c <= '9' && c >= '0') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x * f;
}
int n, stk[N], top;
inline void print1(int x){cout << x << endl; return ;}
inline void work()
{
top = 0;
n = read();
string s;
for(int i = 1; i <= n; i ++)
{
cin >> s;
if(s == "push") stk[++ top] = read();
if(s == "pop") {if(top == 0) puts("Empty"); else top --;}
if(s == "query") {if(top == 0) puts("Anguei!"); else print1(stk[top]);}
if(s == "size") cout << top << endl;
}
return ;
}
signed main()
{
int T = read();
while(T --) work();
return 0;
}