char Tag[99][99]={"OUT OF MAIN PANEL"};
X[99],Y[99],V[99],W[99],c[99],w;
P(p){
	char t[99],d[99];
	c[p]=0;
	for(;w++,scanf("%[^/>]>%d,%d,%d,%d<",Tag[w],X+w,Y+w,V+w,W+w,d);){
		c[p]++;
		P(w);
		if(scanf("%[^>]>%[<]",t,d)!=2){
			w++;
			break;
		}
	}
	w--;
}
main(n,x,y,i){
	for(;scanf("%d\n<",&n)*n;){
		P(w=0);
		for(;n--;){
			scanf("%d%d",&x,&y);
			for(i=w+1;--i;){
				if(x>=X[i]&&y>=Y[i]&&x<=V[i]&&y<=W[i])
					break;
			}
			printf("%s %d\n",Tag[i],c[i]);
		}
	}
}