//* Problem  : 1222 - Friends
//* Contest  : acm.tju.edu.cn
//* Origin   : University of Ulm Local Contest 1999
//* Type     : Solution
//* Date     : 2008.06.06
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 8.0

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

#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <iostream>
using namespace std;
#define int64 long long
#define INF 1000000000
#define EPS 1E-8

#define ALL(a) a.begin(), a.end()
#define PB(a, v) a.push_back(v)
#define MP(a,b) make_pair(a, b)
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
#define FORO(i, obj) for (int i = 0; i < (int)(obj.size); i++)

char s[1000]; int pos;

int parse_expr();

int parse_mul()
{
	int res = 0;
	if (s[pos] == '(')
	{
		pos++;
		res = parse_expr(); 
		pos++;
	}
	else
	{
		pos++;
		while (s[pos] != '}')
			res |= 1<<(s[pos++] - 'A');
		pos++;
	}
	return res;
}

int parse_add()
{
	int res = parse_mul();
	while (s[pos] == '*')
	{
		pos++;
		int t = parse_mul();
		res &= t;
	}
	return res;
}

int parse_expr()
{
	int res = parse_add();
	while (s[pos] == '+' || s[pos] == '-')
	{
		if (s[pos] == '+')
		{
			pos++;
			int t = parse_add();
			res |= t;
		}
		else
		{
			pos++;
			int t = parse_add();
			res = res - (t & res);
		}
	}
	return res;
}

int main()
{
#ifdef _DEBUG
	freopen("1166.in", "r", stdin);
#endif
	while (scanf("%s", s) == 1)
	{
		pos = 0;
		int res = parse_expr();
		printf("{");
		for (int i = 0; i < 26; i++)
			if (res & (1<<i)) putchar(i+'A');
		printf("}\n");
	}
	return 0;
}
