#include <iostream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

class B{
public:
  int x1, y1, x2, y2;
  string to;
  B(){}
  B(int x1, int y1, int x2, int y2, string to) : x1(x1), y1(y1), x2(x2), y2(y2), to(to) {}
};

int n, h, w, b[100], m;
vector<B> buttons[100];
string name[100];
map<string, int> stoi;

int clicked(int x, int y, int p){
  for(int i=0;i<b[p];i++){
    B but = buttons[p][i];
    if(but.x1 <= x && x <= but.x2 && but.y1 <= y && y <= but.y2) return stoi[but.to];
  }
  return -1;
}

main(){
  while(cin >> n && n){
    stoi.clear();
    for(int i=0;i<n;i++) buttons[i].clear();
    cin >> w >> h;
    for(int i=0;i<n;i++){
      cin >> name[i];
      cin >> b[i];
      stoi[name[i]] = i;
      for(int j=0;j<b[i];j++){
        B in;
        cin >> in.x1 >> in.y1 >> in.x2 >> in.y2 >> in.to;
        buttons[i].push_back(in);
      }
    }
    cin >> m;
    int p = 0;
    vector<int> buf;
    buf.push_back(0);
    for(int i=0;i<m;i++){
      string str;
      cin >> str;
      if(str == "forward"){
        if(p+1 < buf.size()) p++;
      }else if(str == "back"){
        if(p != 0) p--;
      }else if(str == "show"){
        cout << name[buf[p]] << endl;
      }else{
        int x, y;
        cin >> x >> y;
        int next = clicked(x, y, buf[p]);
        if(next == -1) continue;
        if(p+1 != buf.size()) buf.erase(buf.begin() + p+1);
        buf.push_back(next);
        p++;
      }
    }
  }
}