#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define _D(p) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p)<<std::endl;
#define _D2(p,q) std::cout<<"L"<<__LINE__<<" : " #p " = "<<(p) << ", " #q " = "<<(q)<<std::endl;
#define _DN(v) std::cout<<"L"<<__LINE__<<" : " #v " = ["; rep(i,(v).size()) {std::cout<<v[i]<<(i==v.size()-1?"":", ");}std::cout<<"]"<<std::endl;
#define _DNN(v) std::cout<<"L"<<__LINE__<<" : " #v " = [" << std::endl; rep(i,(v).size()) {std::cout<<"	[";rep(j,(v)[0].size()){std::cout<<v[i][j]<<(j==v[0].size()-1?"":", ");}std::cout<<"],"<<std::endl;}std::cout<<"]"<<std::endl;
 
using namespace std;
 
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
 
const int INF=1<<29;
const double EPS=1e-9;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};


pair<char, int> formula(string &s, int pos) {

	if (s[pos] == 'T') {
		return mp('T', pos + 1);
	} else if (s[pos] == 'F'){
		return mp('F', pos + 1);
	}

	if (s[pos] == '-' && (pos <= s.size() - 2)) {
		if (s[pos + 1] != '>') {	
			pair<char, int> r = formula(s, pos + 1);
			char ret;
			if (r.first == 'T') {
				ret = 'F';
			} else {
				ret = 'T';
			}
			return mp(ret, r.second);	
		}
	}

	pos++; // skip '('
	char mode;
	pair<char, int> result1 = formula(s, pos);
	if (s[result1.second] == '*') {
		pos = result1.second + 1;
	} else if (s[result1.second] == '+') {
		pos = result1.second + 1;
	} else if (s[result1.second] == '-') {
		pos = result1.second + 2;
	}
	mode = s[result1.second];
	pair<char, int> result2 = formula(s, pos);
	pos = result2.second + 1; //skip ')'

	char ret;
	if (mode == '*') {

		if (result1.first == 'T' && result2.first == 'T') ret = 'T';
		if (result1.first == 'T' && result2.first == 'F') ret = 'F';
		if (result1.first == 'F' && result2.first == 'T') ret = 'F';
		if (result1.first == 'F' && result2.first == 'F') ret = 'F';
	} else if (mode == '+') {

		if (result1.first == 'T' && result2.first == 'T') ret = 'T';
		if (result1.first == 'T' && result2.first == 'F') ret = 'T';
		if (result1.first == 'F' && result2.first == 'T') ret = 'T';
		if (result1.first == 'F' && result2.first == 'F') ret = 'F';
	} else {
		if (result1.first == 'T' && result2.first == 'T') ret = 'T';
		if (result1.first == 'T' && result2.first == 'F') ret = 'F';
		if (result1.first == 'F' && result2.first == 'T') ret = 'T';
		if (result1.first == 'F' && result2.first == 'F') ret = 'T';
	}
	return mp(ret, pos);
	

} 


bool equation(const string &s) {
	int temp;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '=') {
			temp = i;
			break;
		}
	}
	string sl, sr;
	sl = s.substr(0, temp);
	sr = s.substr(temp + 1);

	pair<char, int> resultl = formula(sl, 0);
	pair<char, int> resultr = formula(sr, 0);
	return resultl.first == resultr.first;
}


int main(int argc, char const *argv[]) {
	while(1) {
		string s;
		cin >> s;
		if (s == "#") break;

		set<string> sset;




		char alphabets[11] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' ,'j', 'k'};
		for (int i = 0; i < 1 << 11; ++i) {
			string now = s;
			for(int j = 0; j < 11; j++) { // j bit
				for (int k = 0; k < now.size(); ++k) {
					if (now[k] == alphabets[j]) {
						now[k] = (i >> j & 1) ? 'T' : 'F';
					}
				}
			}
			sset.insert(now);
		}

		bool flag = true;
		for (auto &e : sset) {
			bool result = equation(e);
			if (!result) {
				flag = false;
				break;
			}
		}

		if (flag) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}


	}
	return 0;
}

Measured memory_bytes: 1656