// Aizu 1012: Operations with Finite Sets
// 2017.9.23 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 1000

int set[5][110], len[5];
int uSet[MAX], uLen;
int ans[MAX], aLen;
char buf[MAX], *p;

int cmp(int *a, int *b) { return *a - *b; }
int expr(int *a);

int reform(int *a, int alen)
{
	int i, j;

	if (alen <= 0) return 0;
	qsort(a, alen, sizeof(int), cmp);
	for (i = 0, j = 1; j < alen; j++) {
		if (a[j] != a[i]) {
			if (++i != j) a[i] = a[j];
		}
	}
	return i+1;
}

int bsch(int x, int *a, int alen)
{
	int m, l = 0, r = alen-1;

    while (l < r) {
        m = (l + r) >> 1;
        if (*(a+m) < x) l = m + 1; else r = m;
    }
	return *(a+l) == x;
}

int factor(int *a)
{
	int i, l, id, f = 0;

	if (*p == '(') { p++; l = expr(a); p++; }
	else if (*p >= 'A' && *p <= 'E') {
		id = *p++ - 'A', l = len[id];
		memcpy(a, set[id], sizeof(int)*l);
	} else if (*p == 'c') {
		p++; if (*p < 'A' || *p > 'E') while (1);  // Panic
		id = *p++ - 'A';
		for (l = i = 0; i < uLen; i++) {
			if (!bsch(uSet[i], set[id], len[id])) a[l++] = uSet[i];
		}
	}
	return l;
}

int expr(int *x)
{
	int i, lx, ly, lz, op;
	int *y, *z;

	lx = factor(x);
	while (1) {
		op = *p;
		if (op == 'u' || op == 'i' || op == 'd' || op == 's') p++;
		else break;
		y = calloc(MAX, sizeof(int));
		ly = factor(y);
		z = calloc(MAX, sizeof(int)); lz = 0;
		if (op == 'u') {
			memcpy(z, x, sizeof(int)*lx);
			memcpy(z + lx, y, sizeof(int)*ly);
			lz = reform(z, lx + ly);
		} else if (op == 'i') {
			for (i = 0; i < lx; i++) {
				if (bsch(x[i], y, ly)) z[lz++] = x[i];
			}
		} else if (op == 'd') {
			for (i = 0; i < lx; i++) {
				if (!bsch(x[i], y, ly)) z[lz++] = x[i];
			}
		} else {  // op == 's'
			for (i = 0; i < lx; i++) {
				if (!bsch(x[i], y, ly)) z[lz++] = x[i];
			}
			for (i = 0; i < ly; i++) {
				if (!bsch(y[i], x, lx))	z[lz++] = y[i];
			}
		}
		memcpy(x, z, sizeof(int)*lz);
		lx = reform(x, lz);
		free(z);
		free(y);
	}
	return lx;
}

int main()
{
	int n, i, id, a;
	char s[5];

	while (1) {
		memset(len, 0, sizeof(len)), uLen = 0;
		while (1) {
			if (scanf("%s%d", s, &n) != 2) return 0;
			if (*s == 'R') break;
			id = *s - 'A', len[id] = n;
			for (i = 0; i < n; i++) scanf("%d", &a), set[id][i] = a, uSet[uLen++] = a;
			qsort(set[id], n, sizeof(int), cmp);
		}
		uLen = reform(uSet, uLen);

		scanf("%s", buf); p = buf;
		aLen = expr(ans);
		aLen = reform(ans, aLen);
		if (aLen == 0) putchar('\n');
		else {
			printf("%d", ans[0]);
			for (i = 1; i < aLen; i++) printf(" %d", ans[i]);
			putchar('\n');
		}
	}
	return 0;
}