void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			set = new boolean[5][500];
			u = new boolean[500];
			ref = new HashMap<Integer, Integer>();
			n = 0;
			int[] rev = new int[500];
			for(;;){
				char ch = sc.next().charAt(0);
				int k = sc.nextInt();
				if(ch=='R')break;
				while(k--!=0){
					int x = sc.nextInt();
					if(!ref.containsKey(x)){
						rev[n] = x;
						ref.put(x, n++);
					}
					set[ch-'A'][ref.get(x)] = true;
				}
			}
			s = (sc.next()+"$").toCharArray();
			id = 0;
			Arrays.fill(u, true);
			boolean[] res = exp();
			PriorityQueue<Integer> q = new PriorityQueue<Integer>();
			for(int i=0;i<n;i++)if(res[i])q.add(rev[i]);
			if(q.isEmpty())System.out.println("NULL");
			else {
				System.out.print(q.poll());
				while(!q.isEmpty())System.out.print(" "+q.poll());
				System.out.println();
			}
		}
	}