#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <cctype>



#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
//#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MAX = 200010;
int MOD = (ll)1000000000 + 7;
ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<ll, int>P;
typedef string::const_iterator State;
class ParseError {};
set<int>S[10];
set<int> expr(State& begin);
set<int> factor(State& begin);
set<int> num(State& begin);
set<int>uni(set<int>X, set<int>Y) {
	set<int>res;
	for (auto x : X)res.insert(x);
	for (auto y : Y)res.insert(y);
	return res;
}
set<int>inter(set<int>X, set<int>Y) {
	set<int>res = X;
	for (auto x : X) {
		if (Y.find(x) == Y.end()) {
			res.erase(x);
		}
	}
	return res;
}
set<int>diff(set<int>X, set<int>Y) {
	set<int>res = X;
	for (auto x : X) {
		if (Y.find(x) != Y.end()) {
			res.erase(x);
		}
	}
	return res;
}
set<int> sym(set<int>X, set<int>Y) {
	set<int>res;
	for (auto x : X) {
		if (Y.find(x) == Y.end()) {
			res.insert(x);
		}
	}
	for (auto y : Y) {
		if (X.find(y) == X.end()) {
			res.insert(y);
		}
	}
	return res;
}
set<int>comp(set<int>X, set<int>U) {
	return diff(U, X);
}
set<int>U;

set<int>expr(State & begin) {
	set<int>ret = factor(begin);
	while (*begin == 'u' || *begin == 'i' || *begin == 'd' || *begin == 's') {
		if (*begin == 'u') {
			begin++;
			ret = uni(ret, factor(begin));
		}
		else if (*begin == 'i') {
			begin++;
			ret = inter(ret, factor(begin));
		}
		else if (*begin == 'd') {
			begin++;
			ret = diff(ret, factor(begin));
		}
		else if (*begin == 's') {
			begin++;
			ret = sym(ret, factor(begin));
		}
	}
	return ret;
}
// 乗算除算の式をパースして、その評価結果を返す。
set<int> factor(State & begin) {
	set<int>ret;
	if (*begin == '(') {
		begin++;
		ret = expr(begin);
		begin++;
		return ret;
	}
	else if (*begin == 'c') {
		begin++;
		ret = comp(factor(begin), U);
		return ret;
	}
	else {
		ret = num(begin);
		return ret;
	}
}


// 数字の列をパースして、その数を返す。
set<int> num(State & begin) {
	set<int>ret = S[*begin - 'A'];
	begin++;
	return ret;
}


signed main() {
	char c;
	while (cin >> c) {
		int n; cin >> n;

		if (c == 'R' && n == 0) {
			string str; cin >> str;
			str += '=';
			State begin = str.begin();

			set<int>ans = expr(begin);
			if (ans.size() == 0) {
				print("NULL");
			}
			else {
				auto itr = ans.begin();
				while (itr != ans.end()) {
					cout << *itr;
					itr++;
					if (itr != ans.end()) {
						cout << " ";
					}
				}
				cout << endl;
			}
			U = {};
			REP(i, 5) {
				S[i] = {};
			}
			continue;
		}
		REP(i, n) {
			int x; cin >> x;
			S[c - 'A'].insert(x);
			U.insert(x);
		}
	}
}


Measured memory_bytes: 3020