import scala.annotation.tailrec
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App{
  solve()
  @tailrec def solve(): Unit = {
    val n = readInt()
    if (n == 0) {
      return
    }
    val Array(h, w) = readLine.trim.split(' ').map(_.toInt)
    val pages = List.tabulate(n){_ ⇒
      val Array(title, b) = readLine.trim.split(' ')
      val buttons = List.tabulate(b.toInt){_ ⇒
        val Array(left, up, right, botton, label) = readLine.trim.split(' ')
        Button(label, left.toInt, up.toInt, right.toInt, botton.toInt)
      }
      title → new Page(title, buttons)
    }
    var browser = new Browser(pages.toMap, pages.head._2)
    val click = """click (\d+) (\d+)""".r
    for (_ ← 0 until readInt) {
      readLine.trim match {
        case "back" ⇒ browser = browser.back
        case "forward" ⇒ browser = browser.forward
        case "show" ⇒ println(browser.show)
        case click(x, y) ⇒ browser = browser.click(Point(x.toInt, y.toInt))
        case _ ⇒ ???
      }
    }
    solve()
  }
  class Browser(private val pages: String ⇒ Page, private val history: History) {
    def this(pages: String ⇒ Page, top: Page){
      this(pages, new History(top))
    }
    def click(point: Point): Browser = {
      history.current.click(point) match {
        case None ⇒ this
        case Some(next) ⇒ new Browser(pages, history.move(pages(next)))
      }
    }
    def back: Browser = new Browser(pages, history.movePrev)
    def forward: Browser = new Browser(pages, history.moveNext)
    def show: String = history.current.title
  }
  case class Point(x: Int, y: Int)
  case class Button(label: String, left: Int, up: Int, right: Int, bottom: Int) {
    def isPushed(point: Point): Boolean = (left to right).contains(point.x) && (up to bottom).contains(point.y)
  }
  class Page(val title: String, val button: List[Button]) {
    def click(point: Point): Option[String] = {
      button.find(_.isPushed(point)).map(_.label)
    }
  }
  case class History(prev: List[Page], current: Page, next: List[Page]) {
    def this(current: Page) {
      this(Nil, current, Nil)
    }
    def movePrev: History = {
      prev match {
        case Nil ⇒ this
        case h::t ⇒ History(t, h, current::next)
      }
    }
    def moveNext: History = {
      next match {
        case Nil ⇒ this
        case h::t ⇒ History(current::prev, h, t)
      }
    }
    def move(page: Page): History = History(current::prev, page, Nil)
  }
}
