
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef set<char> SC;

int abs(int a)
{
	return a > 0 ? a : -a;
}

//ifstream in("boole.in");
#define in cin

VI opos, m, val;
VS output;
string s;
int code;
int pos;

int eval()
{
    if (pos >= (int)s.size())
        return 0;
    if ('a' <= s[pos] && s[pos] <= 'z')
    {
        int ret = val[m[s[pos]]];
        output[code][opos[pos]] = '0' + ret;
        pos++;
        return ret;
    }
    if (s[pos] == '(' && s[pos+1] == '!')
    {
        int here = pos+1;
        pos += 2;
        int ret = eval();
        output[code][opos[here]] = '0' + 1 - ret;
        pos++;
        return 1-ret;
    }
    if (s[pos] == '(')
    {
        pos++;
        int val1 = eval();
        int here;
        char op;
        if (s[pos] == '&' || s[pos] == '|')
        {
            op = s[pos];
            here = pos;
            pos++;
        }
        if (s[pos] == '-' || s[pos] == '<')
        {
            op = s[pos];
            here = pos+1;
            pos += 3;
        }
        int val2 = eval();
        int ret;
        if (op == '&')
            ret = val1 * val2;
        if (op == '|')
            ret = max(val1, val2);
        if (op == '<')
            ret = 1 - abs(val1 - val2);
        if (op == '-')
            ret = max(1 - val1, val2);
        pos++;
        output[code][opos[here]] = '0' + ret;
        return ret;
    }
    return 1;
}

int main()
{
    string line;
    while (getline(in, line))
    {
        cout << line << endl;
        s = "";
        opos.clear();
        SC chars;
        m.assign(256, -1);
        for (int i=0; i<(int)line.size(); i++)
            if (line[i] != ' ')
            {
                opos.push_back(i);
                s.push_back(line[i]);
                if ('a' <= line[i] && line[i] <= 'z')
                    chars.insert(line[i]);
            }
        s.append("           ");
        int idx = 0;
        for (SC::iterator it = chars.begin(); it != chars.end(); ++it, idx++)
            m[*it] = idx;
        val.resize(idx);
        int upto = 1 << idx;
        output.assign(upto, string(line.size(), ' '));
        for (code=0; code<upto; code++)
        {
            int c = code;
            for (int i=idx-1; i>=0; i--)
            {
                val[i] = c % 2;
                c /= 2;
            }
            pos = 0;
            eval();
        }
        for (int i=0; i<(int)output.size(); i++)
            cout << output[i] << endl;
        cout << endl;
    }
    return 0;
}
