require 'rexml/document'

class REXML::Element
    def check(x, y)
        init if !@initialized
        return nil if x < @x1 || @x2 < x || y < @y1 || @y2 < y
        children = elements
        puts "#{name} #{children.size}" if !children.any? {|c| c.check(x, y)}
        return true
    end

    def init
        @x1, @y1, @x2, @y2 = text.split(?,).map(&:to_i)
        @initialized = true
    end
end

loop do
    n = gets.to_i
    break if n == 0
    xml = REXML::Document.new(gets.chomp)
    main_panel = xml.elements['/main']

    n.times do
        x, y = gets.split.map(&:to_i)
        puts "OUT OF MAIN PANEL 1" if !main_panel.check(x, y)
    end
end