#include <iostream>
#include <cassert>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>

using namespace std;

string line;
int pos;

#define file cin

struct op {
	op *left, *right;
	int type;
	int pos;
};

void next_char() {
	pos++;
	while( line[pos] == ' ' )
		pos++;
}

const int NEG = 1;
const int AND = 2;
const int OR = 3;
const int IMPL = 4;
const int EQU = 5;

vector<int > used;

op *parse() {
	op *res = 0;
	if( line[pos] == '(' ) {
		next_char();
		if( line[pos] == '!' ) {
			res = new op();
			res->pos = pos;
			next_char();
			res->type = NEG;
			res->left = 0;
			res->right = parse();
		}
		else {
			res = new op();
			res->left = parse();
			if( line[pos] == '|' ) {
				res->type = OR;
				res->pos = pos;
				next_char();
			}
			else if( line[pos] == '&' ) {
				res->type = AND;
				res->pos = pos;
				next_char();
			}
			else if( line[pos] == '-' ) {
				res->type = IMPL;
				next_char();
				res->pos = pos;
				next_char();
				next_char();
			}
			else if( line[pos] == '<' ) {
				res->type = EQU;
				next_char();
				res->pos = pos;
				next_char();
				next_char();				
			}
			res->right = parse();
		}
		assert( line[pos] == ')' );
		next_char();
	}
	else {
		res = new op();
		res->left = res->right = 0;
		res->type = line[pos] - 'a';
		used.push_back( res->type );
		res->pos = pos;
		next_char();
	}
	return res;
}

int value[200];
op *tree;

bool eval( op *tree ) {
	bool res;
	if( tree->left == 0 && tree->right == 0 ) {
		res = value[tree->type];
	}
	else if( tree->left == 0 ) {
		res = !eval( tree->right );
	}
	else {
		bool l = eval( tree->left );
		bool r = eval( tree->right );
		if( tree->type == AND ) {
			res = l && r;
		}
		else if( tree->type == OR ) {
			res = l || r;
		}
		else if( tree->type == IMPL ) {
			res = (!l) || r;
		}
		else if( tree->type == EQU ) {
			res = (!l) ^ r;
		}
	}

	line[tree->pos] = res + '0';
	return res;
}

void eval( int i ) {
	if( i == used.size() ) {
		eval( tree ); 
		cout << line << endl;
		return;
	}
	value[ used[i] ] = 0;
	eval( i+1 );
	value[ used[i] ] = 1;
	eval( i+1 );
}

int main() {
	//ifstream file( "boole.in" );
	while( getline( file, line ) ) {
		pos = -1;
		next_char();
		line += "#";
		used.clear();
		tree = parse();

		line = line.substr( 0, line.size()-1 );
		cout << line << endl;
		line = string( line.size(), ' ' );
		sort( used.begin(), used.end() );
		used.erase( unique( used.begin(), used.end() ), used.end() );
		eval( 0 );
		cout << endl;
	}
	return 0;
}
