import std.algorithm;
import std.array;
import std.stdio;
import std.conv;
import std.container;
import std.typecons;
import std.string;

alias Tuple!(string, "rest", int[], "data") Context;

void main(){
	int[][5] sets;
	auto U = new RedBlackTree!(int, "a < b", false)();
    while(true){
        auto line = readln();
        if(line == "") break;
		
        auto input = line.split();
        if(input[0] == "R"){
            exp(readln.chomp, sets, U[].array).data.map!(to!string).join(" ").writeln;
			sets = (int[][5]).init;
			U.clear;
			continue;
        }
        char c = input[0][0];
        foreach(elem; readln.split.map!(to!int)){
            sets[c - 'A'] ~= elem;
            U.insert(elem);
        }
		sets[c - 'A'].sort();
    }
}

Context exp(string input, int[][5] sets, int[] U){
        Context r = id(input, sets, U);
		while(true){
			if(r.rest.length == 0) break;
			if(r.rest[0] == ')') break;
  	        char op = r.rest[0];
        	Context rhs = id(r.rest[1..$], sets, U);
    	    r.rest = rhs.rest;
	        final switch(op){
           	 	case 'u':
            	    r.data = (r.data.setUnion(rhs.data).array.redBlackTree!false)[].array;
        	        break;
    	        case 'i':
   	             r.data = r.data.setIntersection(rhs.data).array;
                	break;
            	case 'd':
                	r.data = r.data.setDifference(rhs.data).array;
            	    break;
         	    case 's':
                	r.data = r.data.setSymmetricDifference(rhs.data).array;
            	    break;
            }
	    }
        return r;
}

Context id(string input, int[][5] sets, int[] U){
	if(input[0] == '('){
		Context r = exp(input[1..$], sets, U);
		r.rest = r.rest[1..$];
		return r;
	}else if(input[0] == 'c'){
        return Context(input[2..$], U.setDifference(sets[input[1] - 'A']).array);
    }else{
        return Context(input[1..$], sets[input[0] - 'A']);
    }
}