void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			sc.next();sc.next();
			page = new R[n];
			ref = new TreeMap<String, Integer>();
			id = 0;
			for(int i=0;i<n;i++){
				int x = get(sc.next());
				int k = sc.nextInt();
				while(k--!=0){
					page[x].l.add(new B(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.next()));
				}
			}
			int m = sc.nextInt();
			R[] h = new R[m];
			h[0] = page[0];
			int pos = 0;
			int t = 1;
			while(m--!=0){
				String cmd = sc.next();
				if(cmd.equals("show")){
					System.out.println(h[pos].name);
				}
				else if(cmd.equals("back")){
					pos = Math.max(0, pos-1);
				}
				else if(cmd.equals("forward")){
					pos = Math.min(t-1, pos+1);
				}
				else {
					String hit = h[pos].click(sc.nextInt(), sc.nextInt());
					if(hit.equals(""))continue;
					int x = ref.get(hit);
					h[++pos] = page[x];
					t = pos+1;
				}
			}
		}
	}