import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a[] = new int[100010] , tt = -1;
int q = sc.nextInt();
while(q-- != 0){
String s = sc.next();
if("push".equals(s)) a[++tt] = sc.nextInt();
else if("pop".equals(s)) tt --;
else if("query".equals(s)) System.out.println(a[tt]);
else System.out.println(tt == -1 ? "YES":"NO");
}
}
}