//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

typedef string::const_iterator State;
class ParseError {};
VI factor(State&);
VI term(State&);

map<char, VI> mp;
VI all;

// begin???expected?????????????????????begin?????????????????????
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
            << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

VI uni(VI a, VI b) {
	VI ret;
	for(int i: a) ret.PB(i);
	for(int i: b) ret.PB(i);
	sort(ALL(ret));
	ret.erase(unique(ALL(ret)), ret.end());
	return ret;
}

VI inter(VI a, VI b) {
	map<int, int> tmp;
	for(int i: a) tmp[i] = 1;
	VI ret;
	for(int i: b) {
		if(tmp.find(i) != tmp.end()) {
			ret.PB(i);
		}
	}
	return ret;
}

VI diff(VI a, VI b) {
	map<int, int> tmp;
	for(int i: b) tmp[i] = 1;
	VI ret;
	for(int i: a) {
		if(tmp.find(i) == tmp.end()) {
			ret.PB(i);
		}
	}
	return ret;
}

VI symm(VI a, VI b) {
	map<int, int> tmp;
	for(int i: a) tmp[i] = 1;
	for(int i: b) {
		if(tmp.find(i) != tmp.end()) tmp[i] = 2;
		else tmp[i] = 1;
	}
	VI ret;
	for(int i: a) if(tmp[i] == 1) ret.PB(i);
	for(int i: b) if(tmp[i] == 1) ret.PB(i);
	return ret;
}

VI comp(VI a) {
	map<int, int> tmp;
	for(int i: a) tmp[i] = 1;
	VI ret;
	for(int i: all) if(tmp.find(i) == tmp.end()) ret.PB(i);
	return ret;
}

VI expr(State &begin) {
	//cout << "st:" << *begin << endl;
	VI ret = term(begin);
	while(1) {
		//cout << *begin << endl;
		if(*begin == 'u') {
			begin++;
			ret = uni(ret, term(begin));
		} else if(*begin == 'i') {
			begin++;
			ret = inter(ret, term(begin));
		} else if(*begin == 'd') {
			begin++;
			ret = diff(ret, term(begin));
		} else if(*begin == 's') {
			begin++;
			ret = symm(ret, term(begin));
		} else {
			break;
		}
	}

	return ret;
}

VI term(State &begin) {
	//cout << "te:" << *begin << endl;
	if(*begin == 'c') {
		begin++;
		return comp(factor(begin));
	} else {
		return factor(begin);
	}
}

VI factor(State &begin) {
	if(*begin == '(') {
		begin++;
		VI ret = expr(begin);
		consume(begin, ')');
		return ret;
	} else {
		return mp[*begin++];
	}
}

signed main(void)
{
	char name;
	int num;
	while(cin >> name >> num) {
		if(name == 'R' && num == 0) {
			for(auto i: mp) {
				for(int j: i.second) {
					all.PB(j);
				}
			}
			sort(ALL(all));
			all.erase(unique(ALL(all)), all.end());
			string s;
			cin >> s;
			State begin = s.begin();
			VI ans = expr(begin);
			sort(ALL(ans));
			REP(i, ans.size()) {
				cout << ans[i];
				if(i != ans.size()-1) cout << " ";
			}
			if(ans.size() == 0) cout << "NULL";
			cout << endl;
			mp.erase(ALL(mp));
			all.erase(ALL(all));
		}
		REP(i, num) {
			int m;
			cin >> m;
			mp[name].PB(m);
		}
	}

	return 0;
}

Measured memory_bytes: 3136