Problem:
Problem D: Distorted Love

Saying that it is not surprising that people want to know about their love, she has checked up his address, name, age, phone number, hometown, medical history, political party and even his sleeping position, every piece of his personal information. The word "privacy" is not in her dictionary. A person like her is called "stoker" or "yandere", but it doesn't mean much to her.

To know about him, she set up spyware to his PC. This spyware can record his mouse operations while he is browsing websites. After a while, she could successfully obtain the record from the spyware in absolute secrecy.

Well, we want you to write a program which extracts web pages he visited from the records.

All pages have the same size H × W where upper-left corner is (0, 0) and lower right corner is (W, H). A page includes several (or many) rectangular buttons (parallel to the page). Each button has a link to another page, and when a button is clicked the browser leads you to the corresponding page.

His browser manages history and the current page in the following way:

The browser has a buffer of 1-dimensional array with enough capacity to store pages, and a pointer to indicate a page in the buffer. A page indicated by the pointer is shown on the browser. At first, a predetermined page is stored and the pointer indicates that page. When the link button is clicked, all pages recorded in the right side from the pointer are removed from the buffer. Then, the page indicated by the link button is stored into the right-most position of the buffer, and the pointer moves to right. As a result, the user browse the page indicated by the button.

The browser also has special buttons 'back to the previous page' (back button) and 'forward to the next page' (forward button). When the user clicks the back button, the pointer moves to left, and the user clicks the forward button, the pointer moves to right. But in both cases, if there are no such pages in the buffer, nothing happen.

The record consists of the following operations:

click x y

It means to click (x, y). If there is a button on the point (x, y), he moved to the corresponding page. If there is nothing in the point, nothing happen. The button is clicked if x1 ≤ x ≤ x2 and y1 ≤ y ≤ y2 where x1, x2 means the leftmost and rightmost coordinate and y1, y2 means the topmost and bottommost coordinate of the corresponding button respectively.

back

It means to click the Back button.

forward

It means to click the Forward button.

In addition, there is a special operation show. Your program should print the name of current page for each show operation.

By the way, setting spyware into computers of others may conflict with the law. Do not attempt, or you will be reprimanded by great men.

Input

Input consists of several datasets.

Each dataset starts with an integer n which represents the number of pages in the dataset.

Next line contains two integers W and H.

Next, information of each page are given. Each page starts with a string of characters and b[i], the number of buttons the page has. Following b[i] lines give information of buttons. Each button consists of four integers representing the coordinate (x1, y1) of upper left corner and the coordinate (x2, y2) of lower right corner of the button and a string of characters, which represents the name of page that the link of the button represents.

Next, the number of operation m is given. Following m lines represent the record of operations. Please see the above description for the operation.

The first page is stored in the buffer at first.

Input ends when n = 0.

Output

For each dataset, output the name of current page for each show operation.

Constraints

1 ≤ n ≤ 100

b[i] ≤ 100

1 ≤ the number of characters in the name ≤ 20

Buttons are not touch, overlapped nor run over from the browser.

Sample Input

3
800 600
index 1
500 100 700 200 profile
profile 2
100 100 400 200 index
100 400 400 500 link
link 1
100 100 300 200 index
9
click 600 150
show
click 200 450
show
back
back
show
forward
show
0

Output for the Sample Input

profile
link
index
profile

Solution in C# (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		while(true){
			int n=int.Parse(Console.ReadLine());
			if(n==0)break;
			Sol mySol =new Sol(n);
			mySol.Solve();
		}
	}
}

class Sol{
	public void Solve(){
		Dictionary<String,Page> D=new Dictionary<String,Page>();
		
		List<String> buf=new List<String>();
		String EOB="nullnullnullnullnullnull";
		
		for(int i=0;i<N;i++){
			var s=rsa();
			var P=new Page();
			P.Name=s[0];
			P.LCount=int.Parse(s[1]);
			P.LinkName=new String[P.LCount];
			P.LinkArea=new Area[P.LCount];
			for(int j=0;j<P.LCount;j++){
				s=rsa();
				Area A=new Area(int.Parse(s[0]),int.Parse(s[1]),int.Parse(s[2]),int.Parse(s[3]));
				P.LinkArea[j]=A;
				P.LinkName[j]=s[4];
			}
			D.Add(P.Name,P);
			if(i==0){
				buf.Add(P.Name);
				buf.Add(EOB);
			}
		}
		
		int q=ri();
		String order="";
		int cur=0;
		
		for(int i=0;i<q;i++){
			order=rs();
			switch(order[0]){
				case 'c':
					var ss=order.Split(' ');
					int px=int.Parse(ss[1]);
					int py=int.Parse(ss[2]);
					String trgt="";
					for(int j=0;j<D[buf[cur]].LCount;j++){
						if(D[buf[cur]].LinkArea[j].xmin<=px &&
						   D[buf[cur]].LinkArea[j].xmax>=px &&
						   D[buf[cur]].LinkArea[j].ymin<=py &&
						   D[buf[cur]].LinkArea[j].ymax>=py ){
							trgt=D[buf[cur]].LinkName[j];
							break;
						}
					}
//Console.WriteLine("trgt:{0}",trgt);
					if(trgt!=""){
						cur++;
						buf[cur]=trgt;
						if(cur==buf.Count-1){
							buf.Add(EOB);
						}else{
							buf[cur+1]=EOB;
						}
					}
				break;
				case 'f':
					if(cur+1<buf.Count&&buf[cur+1]!=EOB)cur++;
				break;
				case 'b':
					if(cur-1>=0)cur--;
				break;
				case 's':
					Console.WriteLine(buf[cur]);
				break;
			}
		}
		
	}
	

	int N;
	//int W;
	//int H;
	public Sol(int n_){
		N=n_;
		rs();
		//var d=ria();
		//W=d[0];H=d[1];
	}

	class Page{
		public String Name;
		public String[] LinkName;
		public Area[] LinkArea;
		public int LCount;
		public Page(){
		}
	}
	class Area{
		public int xmin;
		public int xmax;
		public int ymin;
		public int ymax;
		public Area(int in0,int in1,int in2,int in3){
			xmin=in0;
			ymin=in1;
			xmax=in2;
			ymax=in3;
		}
	}


	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}