#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

/*
<四則演算の式> ::= <乗算除算の式> (+ or -) <乗算除算の式> (+ or -) ...
<乗算除算の式> ::= <括弧か数> (* or /) <括弧か数> (* or /) ...
<括弧か数>     ::= '(' <四則演算の式> ')' or <数>
<数>           ::= ...
*/

// 構文解析
using State = string::const_iterator;
class ParseError{};

int number(State &begin);
int term(State &begin);
int factor(State &begin);
int expression(State &begin);

string alp = "abcdefghijk";
int bit;
string curstr;

// 数字の列をパースして，その数を返す
int number(State &begin) {
    int ret = 0;

    if (*begin == 'T') {
        ret = 1;
        ++begin;
    }
    else if (*begin == 'F') {
        ret = 0;
        ++begin;
    }
    else {
        rep(i, alp.size()) {
            if (*begin == alp[i]) {

                if ((bit >> i) & 1) {
                    ret = 1;
                }
                else {
                    ret = 0;
                }

                ++begin;
                break;
            }
        }
    }

    return ret;
}

// 乗算除算の式をパースして，その評価結果を返す
int term(State &begin) {
    if (*begin == '-') {
        begin++;
        return abs(1 - term(begin));
    }
    else {
        return factor(begin);
    }
}

int factor(State &begin) {
    if (*begin == '(') {
        begin++; // '('を飛ばす
        int ret = expression(begin);
        begin++;
        return ret;
    }
    else {
        return number(begin);
    }
}


// 四則演算の式をパースして，その評価結果を返す
int expression(State &begin) {
    int ret = term(begin);

    for (;;) {
        if (*begin == '/') {
            begin++;
            int y = term(begin);
            if (ret and !y) ret = 0;
            else ret = 1;
        }
        else if (*begin == '+') {
            begin++;
            ret |= term(begin);
        }
        else if (*begin == '*') {
            begin++;
            ret &= term(begin);
        }
        else {
            break;
        }
    }

    return ret;
}

int main() {
    string s;
    while (getline(cin, s) and s != "#") {

        string a = "", b = "";
        bool flag = false;

        rep(i, s.size()) {
            if (s[i] == '=') {
                flag = true;
                continue;
            }

            if (!flag) {
                if (i+1<s.size() and s[i] == '-' and s[i+1] == '>') {
                    a += '/';
                    ++i;
                }
                else {
                    a += s[i];
                }
            }
            else {
                if (i+1<s.size() and s[i] == '-' and s[i+1] == '>') {
                    b += '/';
                    ++i;
                }
                else {
                    b += s[i];
                }
            }
        }

        bool ok = true;
        for (bit=0; bit<(1<<alp.size()); ++bit) {
            State A = a.begin();
            State B = b.begin();

            curstr = a;
            int tmpa = expression(A);

            curstr = b;
            int tmpb = expression(B);

            bitset<10> bbb(bit);
            //cerr << tmpa << " " << tmpb << ": " << bbb << endl;

            if (tmpa != tmpb) {
                ok = false;
                break;
            }
        }

        cout << (ok ? "YES" : "NO") << endl;
    }

    return 0;
}



Measured memory_bytes: 3224