#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;


struct Button
{
	int x1, y1, x2, y2;
	string name;
	bool include(int x, int y)
	{
		return x1 <= x && x <= x2
			&& y1 <= y && y <= y2;
	}
	void input()
	{
		cin >> x1 >> y1 >> x2 >> y2 >> name;
	}
};
int main()
{
	int n, m, w, h;
	while (cin >> n, n)
	{
		cin >> w >> h;

		map<string, vector<Button> > page;
		vector<string> buffer;
		rep (i, n)
		{
			string name;
			int b;
			cin >> name >> b;
			if (i == 0)
				buffer.push_back(name);

			while (b--)
			{
				page[name].push_back(Button());
				page[name].back().input();
			}
		}

		cin >> m;
		int pointer = 0;
		while (m--)
		{
			string& b = buffer[pointer];

			string c;
			cin >> c;
			if (c[0] == 'c')
			{
				int x, y;
				cin >> x >> y;
				for (int i = 0; i < page[b].size(); ++i)
				{
					if (page[b][i].include(x, y))
					{
						++pointer;
						buffer.erase(buffer.begin() + pointer, buffer.end());
						buffer.push_back(page[b][i].name);
						break;
					}
				}
			}
			else if (c[0] == 'b')
				pointer = max(0, --pointer);
			else if (c[0] == 'f')
				pointer = min((int)buffer.size() - 1, ++pointer);
			else if (c[0] == 's')
				cout << b << endl;
		}
	}
}