import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;

bool[11] vars;
string input;

bool check() {
    string[] eq = input.split("=");
    bool val(string s) {
        int index = 0;
        bool parse() {
            if (s[index] == 'T') {
                index++;
                return true;
            }
            if (s[index] == 'F') {
                index++;
                return false;
            }
            if ('a' <= s[index] && s[index] <= 'k') {
                bool x = vars[s[index] - 'a'];
                index++;
                return x;
            }
            if (s[index] == '-') {
                index++;
                return (!parse);
            }
            if (s[index] == '(') {
                index++;
                bool x = parse;
                if (s[index] == '*') {
                    index++;
                    bool y = parse;
                    assert(s[index] == ')');
                    index++;
                    return (x & y);
                } else if (s[index] == '+') {
                    index++;
                    bool y = parse;
                    assert(s[index] == ')');
                    index++;
                    return (x | y);
                } else { // 
                    assert(s[index] == '-' && s[index+1] == '>');
                    index += 2;
                    bool y = parse;
                    assert(s[index] == ')');
                    index++;
                    return (y | (!x));
                }
            }
            assert(0);
        }
        return parse;
    }
    return val(eq[0]) == val(eq[1]);
}

void main() {
test: while (true) {
        input = readln.chomp;
        if (input == "#") break;
        for (int i = 0; i < (1 << 11); i++) {
            for (int j = 0; j < 11; j++) {
                vars[j] = (i & (1 << j)) ? true : false;
            }
            if (!check) {
                "NO".writeln;
                continue test;
            }
        }
        "YES".writeln;
    }
}