class Rect
  def initialize(x1,y1,x2,y2)
    @xs = (x1..x2)
    @ys = (y1..y2)
  end
  def include?(x,y)
    @xs.include?(x) and @ys.include?(y)
  end
end

class Link
  attr_reader(:name)
  def initialize(x1,y1,x2,y2,s)
    @rect = Rect.new(x1,y1,x2,y2)
    @name = s
  end
  def hit?(x,y)
    @rect.include?(x,y)
  end
end

class Page
  def initialize(s)
    @name = s
    @links = []
  end
  def add_link(x1,y1,x2,y2,s)
    link = Link.new(x1,y1,x2,y2,s)
    @links << link
  end
  def point(x,y)
    target = @links.find{|link| link.hit?(x,y)}
    return nil if target==nil
    return target.name
  end
end

class PageBuf
  attr_reader(:name)
  attr_accessor(:back, :forward)
  def initialize(name)
    @name = name
    @back = self
    @forward = self
  end
  def set_next(pbuf)
    self.forward = pbuf
    pbuf.back = self
    pbuf
  end
end

loop{
  n = gets.to_i
  break if n==0
  pages = {}
  
  h, w = gets.split.map(&:to_i)
  home = nil
  n.times{
    name, cs = gets.split
    home = name if home==nil
    page = Page.new(name)
    cs.to_i.times{
      args = gets.split
      lname = args.pop
      x1,y1,x2,y2 = args.map(&:to_i)
      page.add_link(x1,y1,x2,y2,lname)
    }
    pages[name] = page
  }
  m = gets.to_i
  pbuf = PageBuf.new(home)
  m.times{
    op, *args = gets.split
    cur = pages[pbuf.name]
    case op
      when "click"
        x, y = args.map(&:to_i)
        link = cur.point(x,y)
        if link
          nbuf = PageBuf.new(link)
          pbuf = pbuf.set_next(nbuf)
        end
      when "back"
        pbuf = pbuf.back
      when "forward"
        pbuf = pbuf.forward
      when "show"
        puts pbuf.name
    end
  }
}
