#include <cstdio>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

string pat = "uids";
map< char, vector<int> > sets;
vector<int> all_sets;

vector<int> operate(vector<int> setA, vector<int> setB, char op, bool isC) {
  sort(setA.begin(), setA.end());
  sort(setB.begin(), setB.end());

  vector<int> res;
  if(op == 'i') {
    set<int> S;
    for(auto x : setA) S.insert(x);

    for(auto x : setB) {
      if(S.count(x)) res.push_back(x);
    }
  }
  if(op == 'u') {
    set<int> S;
    for(auto x : setA) S.insert(x), res.push_back(x);

    for(auto x : setB) {
      if(!S.count(x)) res.push_back(x);
    }
  }
  if(op == 'd') {
    set<int> S;
    for(int i=0; i<setB.size(); i++) S.insert(setB[i]);

    for(int i=0; i<setA.size(); i++) {
      if(!S.count(setA[i])) {
	res.push_back(setA[i]);
      }
    }
  }
  if(op == 's') {
    map<int, int> mp;
    for(auto x : setA) mp[x]++;
    for(auto x : setB) mp[x]++;

    for(auto x : mp) {
      if(x.second > 1) continue;
      res.push_back(x.first);
    }
  }
  if(op == 'c') {
    set<int> S;
    for(auto x : setA) S.insert(x);

    for(auto x : all_sets) {
      if(!S.count(x)) res.push_back(x);
    }
  }

  if(isC) {
    return operate(res, vector<int>(), 'c', false);
  }
  else {
    return res;
  }
}

vector<int> parse(string s, int l, int r) {
  // fprintf(stderr, "parse [%d, %d)\n", l, r);
  int paren = 0;
  bool isC = false;
  char op = 'u';
  vector<int> ret;
  for(int i=l; i<r; i++) {
    if(s[i] == 'c') isC ^= true;
    else if(s[i] == '(') {
      paren++;
      int nl = i++, nr = -1;
      for(; paren > 0 and i < s.length(); i++) {
	if(s[i] == '(') paren++;
	if(s[i] == ')') paren--;
      }
      nr = i--;
      // fprintf(stderr, "operate [%d %d): %d\n", nl+1, nr-1, isC);
      ret = operate(ret, parse(s, nl+1, nr-1), op, isC);
      isC = false;
    }
    else if(pat.find(s[i]) != string::npos) {
      // fprintf(stderr, "set operator: %c\n", s[i]);
      op = s[i];
    }
    else {
      // fprintf(stderr, "char %c: isC = %d\n", s[i], isC);
      // fprintf(stderr, "operate %c: %d\n", s[i], isC);
      ret = operate(ret, sets[ s[i] ], op, isC);
      isC = false;
    }
    // fprintf(stderr, "temp state at i = %d:", i);
    // for(auto x : ret) fprintf(stderr, " %d", x);
    // cerr << endl;
  }
  // fprintf(stderr, "answer of parse [%d, %d):", l, r);
  // for(auto x : ret) fprintf(stderr, " %d", x);
  // cerr << endl;
  return ret;
}

int main() {
  char set_name; int set_size;
  while(cin >> set_name >> set_size) {
    if(set_name == 'R') {
      string expr; cin >> expr;
      int len = expr.size();
      vector<int> ans = parse(expr, 0, len);

      sort(ans.begin(), ans.end());
      if(ans.empty()) cout << "NULL" << endl;
      else {
	for(size_t i=0; i<ans.size(); i++) {
	  cout << ans[i] << " \n"[i+1 == ans.size()];
	}
      }
	
      sets.clear();
      all_sets.clear();
    }
    else {
      sets[set_name] = vector<int>();
      for(int i=0; i<set_size; i++) {
	int num; cin >> num;
	sets[set_name].push_back(num);
      }
      // fprintf(stderr, "input end\n");
      all_sets = operate(all_sets, sets[set_name], 'u', false);
    }
  }
  return 0;
}



Measured memory_bytes: 3220