#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

typedef string::const_iterator State;
const int K = 11;

string format(string s) {
    string t;
    int i = 0;
    while (i < s.size()) {
        if (i + 1 < s.size() && s.substr(i, 2) == "->") {
            t += '@';
            i += 2;
        } else {
            t += s[i];
            i++;
        }
    }
    return t;
}

bool atom(State&, int);
bool term(State&, int);
bool formula(State&, int);

bool atom(State &begin, int bits) {
    // cerr << "atom: " << *begin << endl;

    if (*begin == 'T') {
        begin++;
        return true;
    } else if (*begin == 'F') {
        begin++;
        return false;
    } else {
        assert('a' <= *begin && *begin <= 'k');
        int i = *begin - 'a';
        begin++;
        return (bits >> i) & 1;
    }
}

bool term(State &begin, int bits) {
    // cerr << "term: " << *begin << endl;

    bool ret = formula(begin, bits);

    if (*begin == '*') {
        begin++;
        ret &= formula(begin, bits);
    } else if (*begin == '+') {
        begin++;
        ret |= formula(begin, bits);
    } else {
        assert(*begin == '@');
        begin++;
        int nxt = formula(begin, bits);
        ret = (!ret || nxt);
    }

    return ret;
}

bool formula(State &begin, int bits) {
    // cerr << "formula: " << *begin << endl;
    bool ret;

    if (isalpha(*begin)) {
        ret = atom(begin, bits);
    } else if (*begin == '-') {
        begin++;
        ret = !formula(begin, bits);
    } else {
        assert(*begin == '(');
        begin++;
        ret = term(begin, bits);
        assert(*begin == ')');
        begin++;
    }

    return ret;
}

bool solve(string s) {
    s = format(s); // convert "->" to "@"
    // cerr << s << endl;

    string s1, s2;
    bool reading_s1 = true;
    rep(i, s.size()) {
        if (s[i] == '=') {
            reading_s1 = false;
        } else {
            (reading_s1 ? s1 : s2) += s[i];
        }
    }
    // cerr << s1 << " " << s2 << endl;

    rep(bits, 1 << K) {
        State begin1 = s1.begin();
        State begin2 = s2.begin();
        if (formula(begin1, bits) ^ formula(begin2, bits)) {
            return false;
        }
    }

    return true;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    string s;
    while (cin >> s, s[0] - '#') {
        cout << (solve(s) ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 3268