#include <iostream>
#include <string>
#include <set>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;

typedef map<char, set<int> > mapset;

set<int> atom(string&, mapset&, int&);
set<int> block(string&, mapset&, int&);
set<int> unite(set<int>&, set<int>&);
set<int> intersection(set<int>&, set<int>&);
set<int> difference(set<int>&, set<int>&);
set<int> symmetric_difference(set<int>&, set<int>&);
set<int> parse(string&, mapset&, int&);
set<int> complement(mapset&, set<int>&);

void print(set<int> s) {
    cout << "set: ";
    for (set<int>::iterator it=s.begin(); it!=s.end(); ++it) {
        cout << *it << " ";
    }
    cout << endl;
}

set<int> atom(string &expr, mapset &sets, int &k) {
    set<int> ret(sets[expr[k]]);
    k ++;
    return ret;
}

set<int> block(string &expr, mapset &sets, int &k) {
    set<int> v;
    if (expr[k] == '(') {
        k ++;
        v = parse(expr, sets, k);
        k ++;
        return v;
    } else if (expr[k] == 'c') {
        k ++;
        v = block(expr, sets, k);
        v = complement(sets, v);
        return v;
    } else {
        v = atom(expr, sets, k);
        return v;
    }
}

set<int> unite(set<int> &s1, set<int> &s2) {
    set<int> ret(s1);
    for (set<int>::iterator it=s2.begin(); it!=s2.end(); ++it) {
        ret.insert(*it);
    }
    return ret;
}

set<int> intersection(set<int> &s1, set<int> &s2) {
    set<int> ret;
    for (set<int>::iterator it=s2.begin(); it!=s2.end(); ++it) {
        if (s1.find(*it) != s1.end()) {
            ret.insert(*it);
        }
    }
    return ret;
}

set<int> difference(set<int> &s1, set<int> &s2) {
    set<int> ret(s1);
    for (set<int>::iterator it=s2.begin(); it!=s2.end(); ++it) {
        ret.erase(*it);
    }
    return ret;
}

set<int> symmetric_difference(set<int> &s1, set<int> &s2) {
    set<int> dif1 = difference(s1, s2);
    set<int> dif2 = difference(s2, s1);
    return unite(dif1, dif2);
}

set<int> complement(mapset &sets, set<int> &s1) {
    set<int> U;
    for (mapset::iterator it=sets.begin(); it!=sets.end(); ++it) {
        U = unite(U, it->second);
    }
    return difference(U, s1);
}

set<int> parse(string &expr, mapset &sets, int &k) {
    set<int> v1 = block(expr, sets, k);
    while (k < (int)expr.size() && expr[k] != ')') {
        char op = expr[k];
        k ++;
        set<int> v2 = block(expr, sets, k);
        if (op == 'u') {
            v1 = unite(v1, v2);
        } else if (op == 'i') {
            v1 = intersection(v1, v2);
        } else if (op == 'd') {
            v1 = difference(v1, v2);
        } else if (op == 's') {
            v1 = symmetric_difference(v1, v2);
        }
    }
    return v1;
}

void solve(string &expr, mapset &sets) {
    int k = 0;
    set<int> st = parse(expr, sets, k);
    if (st.empty()) {
        cout << "NULL" << endl;
        return ;
    }
    for (set<int>::iterator it=st.begin(); it!=st.end(); ++it) {
        cout << (it == st.begin() ? "" : " ") << *it;
    }
    cout << endl;
}

int main() {
    char c; int k;
    map<char, set<int> > sets;
    while (cin >> c >> k) {
        if (c != 'R') {
            set<int> st; int t;
            for (int i=0; i<k; ++i) {
                cin >> t;
                st.insert(t);
            }
            sets[c] = st;
        } else {
            string expr;
            cin >> expr;
            solve(expr, sets);

            sets.clear();
        }
    }
    return 0;
}

Measured memory_bytes: 1216