#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

typedef vector <int> VI;
typedef set <int> SI;
typedef map <string, SI> MSI;

MSI M;
VI T;

SI getU() {
    SI res;
    string S[5] = { "A", "B", "C", "D", "E" };
    for ( int i = 0; i < 5; ++ i ) {
        for ( SI::iterator it_i = M[S[i]].begin(); it_i != M[S[i]].end(); ++ it_i ) {
            res.insert( *it_i );
        }
    }
    SI st( res.begin(), res.end() );
    return SI( st.begin(), st.end() );
}

SI getCU( SI A ) {
    SI res;
    SI U = getU();
    for ( SI::iterator it_i = U.begin(); it_i != U.end(); ++ it_i ) {
        bool flag = true;
        for ( SI::iterator it_j = A.begin(); it_j != A.end(); ++ it_j ) {
            if ( *it_j == *it_i ) flag = false;
        }
        if ( flag ) res.insert( *it_i );
    }
    return res;
}

void print_vi( SI s ) {
    if ( s.empty() ) {
        cout << "NULL" << endl;
        return;
    }
    VI v( s.begin(), s.end() );
    for ( VI::iterator it_i = v.begin(); it_i != v.end(); ++ it_i ) {
        cout << *it_i;
        if ( it_i + 1 != v.end() ) {
            cout << " ";
        }
    }
    cout << endl;
}

bool isOP( char c ) {
    if ( c == 'u' ) return true;
    if ( c == 'i' ) return true;
    if ( c == 'd' ) return true;
    if ( c == 's' ) return true;
    return false;
}

string toString( char c ) {
    string res;
    res += c;
    return res;
}

SI getUnion( SI A, SI B ) {
    SI res;
    for ( SI::iterator it_i = A.begin(); it_i != A.end(); ++ it_i ) {
        res.insert( *it_i );
    }
    for ( SI::iterator it_i = B.begin(); it_i != B.end(); ++ it_i ) {
        res.insert( *it_i );
    }
    return res;
}

SI getIntersection( SI A, SI B ) {
    SI res;
    for ( SI::iterator it_i = A.begin(); it_i != A.end(); ++ it_i ) {
        for ( SI::iterator it_j = B.begin(); it_j != B.end(); ++ it_j ) {
            if ( *it_i == *it_j ) res.insert( *it_i );
        }
    }
    return res;
}

SI getDifference( SI A, SI B ) {
    SI res;
    for ( SI::iterator it_i = A.begin(); it_i != A.end(); ++ it_i ) {
        res.insert( *it_i );
    }
    for ( SI::iterator it_i = B.begin(); it_i != B.end(); ++ it_i ) {
        res.erase( *it_i );
    }
    return res;
}

SI getSymmetricDifference( SI A, SI B ) {
    return getUnion( getDifference( A, B ), getDifference( B, A ) );
}

SI solve2( string s, int k ) {
    int n = s.size();

    SI A, B;
    string op;
    // A
    if ( s[k] == '(' ) {
        A = solve2( s, k + 1 );
        k = T[k] + 1;
    } else if ( s[k] == 'c' && s[k+1] == '(' ) {
        A = getCU( solve2( s, k + 2 ) );
        k = T[k+1] + 1;
    } else {
        if ( s[k] == 'c' ) {
            A = getCU( M[toString(s[k+1])] );
            k += 2;
        } else {
            A = M[toString(s[k])];
            k += 1;
        }
    }

    SI res = A;
    while ( k < n && s[k] != ')' ) {
        // O
        op = s[k];
        k ++;
        // B
        if ( s[k] == '(' ) {
            B = solve2( s, k + 1 );
            k = T[k] + 1;
        } else if ( s[k] == 'c' && s[k+1] == '(' ) {
            B = getCU( solve2( s, k + 2 ) );
            k = T[k+1] + 1;
        } else {
            if ( s[k] == 'c' ) {
                B = getCU( M[toString(s[k+1])] );
                k += 2;
            } else {
                B = M[toString(s[k])];
                k += 1;
            }
        }
        if ( op == "u" ) {
            res = getUnion( res, B );
        } else if ( op == "i" ) {
            res = getIntersection( res, B );
        } else if ( op == "d" ) {
            res = getDifference( res, B );
        } else if ( op == "s" ) {
            res = getSymmetricDifference( res, B );
        }
    }

    return res;
}

void solve( string first_name, int first_n ) {
    M.clear();

    // input
    for ( int i = 0; i < first_n; ++ i ) {
        int elm;
        cin >> elm;
        M[first_name].insert( elm );
    }
    string name;
    int n;
    while ( cin >> name >> n ) {
        if ( name == "R" && n == 0 ) break;
        for ( int i = 0; i < n; ++ i ) {
            int elm;
            cin >> elm;
            M[name].insert( elm );
        }
    }
    string exp;
    cin >> exp;

    int m = exp.size();
    T = VI( m, m );
    stack <int> st;
    for ( int i = 0; i < m; ++ i ) {
        if ( exp[i] == '(' ) {
            st.push( i );
        } else if ( exp[i] == ')' ) {
            int left = st.top();
            st.pop();
            int right = i;
            T[left] = right;
        }
    }

    print_vi( solve2( exp, 0 ) );
}

int main() {
    string name;
    int n;
    while ( cin >> name >> n ) {
        solve( name, n );
    }
    return 0;
}

Measured memory_bytes: 0