### subroutines

def get_link(page, x, y)
  for bt in page
    x1, y1, x2, y2, link = bt
    return link if x1 <= x && x <= x2 && y1 <= y && y <= y2
  end
  nil
end

### main

loop do
  n = gets.to_i
  break if n == 0

  w, h = gets.split.map(&:to_i)

  pages = {}
  buffer = []
  nbuf = pos = 0

  n.times do
    title, nb = gets.strip.split
    pages[title] = []
    nb.to_i.times do
      bts = gets.strip.split
      pages[title] << bts[0, 4].map(&:to_i) + [bts[4]]
    end

    if nbuf == 0
      buffer << title
      nbuf = 1
    end
  end
  #p pages

  m = gets.to_i

  m.times do
    ops = gets.split

    case ops[0]
    when 'click'
      x, y = ops[1, 2].map(&:to_i)
      link = get_link(pages[buffer[pos]], x, y)
      if ! link.nil?
        pos += 1
        buffer[pos] = link
        nbuf = pos + 1
      end
    when 'back'
      pos -= 1 if pos > 0
    when 'forward'
      pos += 1 if pos < nbuf - 1
    when 'show'
      puts buffer[pos]
    end
  end
end