#include <stdio.h>

FILE *in;
char s[10000];
char r[10000];
char v[256];
char b[256];
char* pos;
int xpos;

void skipws()
{
	while(s[xpos]==' ') xpos++;
}

int eval()
{
	int val=0;
	int dummy;
	skipws();
	if (s[xpos]<' ') return val;
	dummy=xpos;
	switch(s[xpos])
		{
		case '(':
			xpos++;
			val=eval();
			skipws();
			xpos++;
			break;
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f':
		case 'g':
		case 'h':
		case 'i':
		case 'j':
		case 'k':
		case 'l':
		case 'm':
		case 'n':
		case 'o':
		case 'p':
		case 'q':
		case 'r':
		case 's':
		case 't':
		case 'u':
		case 'v':
		case 'w':
		case 'x':
		case 'y':
		case 'z':
			r[xpos]=b[int(s[xpos])]+1;
			val=b[int(s[xpos])];
			xpos++;
			break;
		case '!':
			xpos++;
			val=(eval())?(0):(1);
			r[dummy]=val+1;
			break;
		default:
			xpos++;
		}
	skipws();
	if (s[xpos]=='-')
		{
			xpos++;
			skipws();
			dummy=xpos++;
			skipws();
			xpos++;
			int val1=eval();
			val=((val)?((val1)?(1):(0)):(1));
			r[dummy]=val+1;
		}
	else if (s[xpos]=='<')
		{
			xpos++;
			skipws();
			dummy=xpos++;
			skipws();
			xpos++;
			int val1=eval();
			val=(val==val1)?(1):(0);
			r[dummy]=val+1;
		}
	else if (s[xpos]=='&')
		{
			dummy=xpos++;
			skipws();
			int val1=eval();
			val=(val&&val1)?(1):(0);
			r[dummy]=val+1;
		}
	else if (s[xpos]=='|')
		{
			dummy=xpos++;
			skipws();
			int val1=eval();
			val=(val||val1)?(1):(0);
			r[dummy]=val+1;
		}
	return val;
}

int main()
{
	in=stdin;
	while(1)
		{
			if (!fgets(s, 10000, in)) break;
			printf("%s", s);
			for(int i=0; i<256; i++)
				{
					v[i]=0; b[i]=0;
				}
			for(int i=0; i<10000; i++) r[i]=0;
			pos=s;
			while(*pos>=' ')
				{
					if ((*pos>='a') && (*pos<='z')) v[int(*pos)]=1;
					pos++;
				}
			while(1)
				{
					xpos=0;
					eval();
					for(int i=0; i<xpos; i++)
						if (!r[i]) printf(" "); else printf("%d", r[i]-1);
					printf("\n");
					int pos='z';
					while(pos>='a')
						{
							if (v[pos])
								{
									b[pos]^=1;
									if (b[pos]) goto weiter1;
								}
							pos--;
						}
					goto weiter2;
				weiter1:;
				}
		weiter2:;
			printf("\n");
		}
	return 0;
}
