#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cassert>
using namespace std;
#define MAX 100
#define rep(i, n) for ( int i = 0; i < n; i++ )

class Button{
public:
  int x1, y1, x2, y2;
  string target;
  Button(int x1, int y1, int x2, int y2, string target):x1(x1), y1(y1), x2(x2), y2(y2), target(target){}
};

class Page{
public:
  string name;
  int H, W;
  vector<Button> B;
  Page(string name="", int W=0, int H=0):name(name), W(W), H(H){}

  string click(int x, int y){
    rep(i, B.size()){
      Button b = B[i];

      if ( b.x1 <= x && x <= b.x2 &&
	   b.y1 <= y && y <= b.y2 ) {
	//assert( b.x1 != x );
	//assert( b.y1 != y );
	//assert( b.x2 != x );
	//assert( b.y2 != y );
	return b.target;
      }
    }
    return name;
  }

  bool over(int a, int b, int c, int d ){
    int p1, p2, p3, p4;
    if ( a <= c ){
      p1 = a; p2 = b; p3 = c; p4 = d;
    } else {
      p1 = c; p2 = d; p3 = a; p4 = b;
    }
    return  p2 >= p3;
  }
  void buttonCheck(){
    for ( int i = 0; i < (int)(B.size())-1; i++ ){
      for ( int j = i+1; j < B.size(); j++ ){
	Button b1 = B[i];
	Button b2 = B[j];
	
	if ( over(b1.x1, b1.x2, b2.x1, b2.x2) &&
	     over(b1.y1, b1.y2, b2.y1, b2.y2) ){
	  assert(false);
	}
	
      }
    }
  }
};

int n, H, W;
Page P[MAX];
map<string, int> PI;


void simulate(){
  int q; cin >> q;
  string com, target;
  int history[10000], x, y, cur, top, forward;
  top = forward = 0;

  cur = 0;
  history[top] = cur;

  rep(p, q){
    cin >> com;
    if ( com == "click" ){
      cin >> x >> y;
      assert( 1 <= x && x <= W );
      assert( 1 <= y && y <= H );
      target = P[cur].click(x, y);
      assert( PI.find(target) != PI.end());
      if ( target != P[cur].name ){
	cur = PI[target];
	history[++top] = PI[target];
	forward = top;
      }
    } else if ( com == "forward" ){
      if ( top < forward){
	top++;
	cur = history[top];
      }
    } else if ( com == "back"){
      if ( top > 0 ){
	top--;
	cur = history[top];
      }
    } else if ( com == "show" ){
      cout << P[cur].name << endl;
    } else assert(false);

  }
}

int main(){
  string name, target;
  int  m, x1, y1, x2, y2;
  while( cin >> n && n ){
    cin >> W >> H;
    assert( 1 <= n && n <= 100 );
    rep(i, n){
      cin >> name >> m;
      assert( name.size() <= 20 );
      char h = name[0];
      assert( !('0' <= h && h <= '9') );
      assert( m <= 100);
      P[i] = Page(name, W, H);
      rep(j, m){
	cin >> x1 >> y1 >> x2 >> y2 >> target;
	assert( 0 <= x1 && x1 <= W);
	assert( 0 <= x2 && x2 <= W);
	assert( 0 <= y1 && y1 <= H);
	assert( 0 <= y2 && y2 <= H);
	P[i].B.push_back(Button(x1, y1, x2, y2, target));
      }
      PI[name] = i;

      P[i].buttonCheck();
    }
    simulate();
  }
}
### Prompt

Please formulate a cpp solution to the following problem:

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.

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.

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.

Example

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

profile
link
index
profile

### Response

```cpp
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cassert>
using namespace std;
#define MAX 100
#define rep(i, n) for ( int i = 0; i < n; i++ )

class Button{
public:
  int x1, y1, x2, y2;
  string target;
  Button(int x1, int y1, int x2, int y2, string target):x1(x1), y1(y1), x2(x2), y2(y2), target(target){}
};

class Page{
public:
  string name;
  int H, W;
  vector<Button> B;
  Page(string name="", int W=0, int H=0):name(name), W(W), H(H){}

  string click(int x, int y){
    rep(i, B.size()){
      Button b = B[i];

      if ( b.x1 <= x && x <= b.x2 &&
	   b.y1 <= y && y <= b.y2 ) {
	//assert( b.x1 != x );
	//assert( b.y1 != y );
	//assert( b.x2 != x );
	//assert( b.y2 != y );
	return b.target;
      }
    }
    return name;
  }

  bool over(int a, int b, int c, int d ){
    int p1, p2, p3, p4;
    if ( a <= c ){
      p1 = a; p2 = b; p3 = c; p4 = d;
    } else {
      p1 = c; p2 = d; p3 = a; p4 = b;
    }
    return  p2 >= p3;
  }
  void buttonCheck(){
    for ( int i = 0; i < (int)(B.size())-1; i++ ){
      for ( int j = i+1; j < B.size(); j++ ){
	Button b1 = B[i];
	Button b2 = B[j];
	
	if ( over(b1.x1, b1.x2, b2.x1, b2.x2) &&
	     over(b1.y1, b1.y2, b2.y1, b2.y2) ){
	  assert(false);
	}
	
      }
    }
  }
};

int n, H, W;
Page P[MAX];
map<string, int> PI;


void simulate(){
  int q; cin >> q;
  string com, target;
  int history[10000], x, y, cur, top, forward;
  top = forward = 0;

  cur = 0;
  history[top] = cur;

  rep(p, q){
    cin >> com;
    if ( com == "click" ){
      cin >> x >> y;
      assert( 1 <= x && x <= W );
      assert( 1 <= y && y <= H );
      target = P[cur].click(x, y);
      assert( PI.find(target) != PI.end());
      if ( target != P[cur].name ){
	cur = PI[target];
	history[++top] = PI[target];
	forward = top;
      }
    } else if ( com == "forward" ){
      if ( top < forward){
	top++;
	cur = history[top];
      }
    } else if ( com == "back"){
      if ( top > 0 ){
	top--;
	cur = history[top];
      }
    } else if ( com == "show" ){
      cout << P[cur].name << endl;
    } else assert(false);

  }
}

int main(){
  string name, target;
  int  m, x1, y1, x2, y2;
  while( cin >> n && n ){
    cin >> W >> H;
    assert( 1 <= n && n <= 100 );
    rep(i, n){
      cin >> name >> m;
      assert( name.size() <= 20 );
      char h = name[0];
      assert( !('0' <= h && h <= '9') );
      assert( m <= 100);
      P[i] = Page(name, W, H);
      rep(j, m){
	cin >> x1 >> y1 >> x2 >> y2 >> target;
	assert( 0 <= x1 && x1 <= W);
	assert( 0 <= x2 && x2 <= W);
	assert( 0 <= y1 && y1 <= H);
	assert( 0 <= y2 && y2 <= H);
	P[i].B.push_back(Button(x1, y1, x2, y2, target));
      }
      PI[name] = i;

      P[i].buttonCheck();
    }
    simulate();
  }
}
```