'use strict';

function token(s) {
  var len = s.length;
  return function (target, pos) {
    return target.substr(pos, len) === s ? [true, s, pos + len] : [false, null, pos];
  };
}

function choice() {
  var parsers = arguments;
  return function (target, pos) {
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = parsers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var parser = _step.value;

        var parsed = parser(target, pos);
        if (parsed[0]) return parsed;
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    return [false, null, pos];
  };
}

function seq() {
  var parsers = arguments;
  return function (target, pos) {
    var result = [];
    var nextPos = pos;
    var _iteratorNormalCompletion2 = true;
    var _didIteratorError2 = false;
    var _iteratorError2 = undefined;

    try {
      for (var _iterator2 = parsers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
        var parser = _step2.value;

        var parsed = parser(target, nextPos);
        if (!parsed[0]) return [false, null, pos];
        result.push(parsed[1]);
        nextPos = parsed[2];
      }
    } catch (err) {
      _didIteratorError2 = true;
      _iteratorError2 = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion2 && _iterator2.return) {
          _iterator2.return();
        }
      } finally {
        if (_didIteratorError2) {
          throw _iteratorError2;
        }
      }
    }

    return [true, result, nextPos];
  };
}

function lazy(f) {
  var parser = void 0;
  return function (target, position) {
    if (!parser) parser = f();
    return parser(target, position);
  };
}

function fmap(parser, f) {
  return function (target, pos) {
    var result = parser(target, pos);
    if (result[0]) {
      return [result[0], f(result[1]), result[2]];
    } else {
      return result;
    }
  };
}

function oneOf(s) {
  var d = {};
  var _iteratorNormalCompletion3 = true;
  var _didIteratorError3 = false;
  var _iteratorError3 = undefined;

  try {
    for (var _iterator3 = s[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
      var c = _step3.value;
      d[c] = c;
    }
  } catch (err) {
    _didIteratorError3 = true;
    _iteratorError3 = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion3 && _iterator3.return) {
        _iterator3.return();
      }
    } finally {
      if (_didIteratorError3) {
        throw _iteratorError3;
      }
    }
  }

  return function (target, pos) {
    var c = target.substr(pos, 1);
    return d[c] ? [true, c, pos + 1] : [false, null, pos];
  };
}

(function (stdin) {
  var formulaP = lazy(function () {
    var andP = fmap(seq(token('('), formulaP, token('*'), formulaP, token(')')), function (x) {
      return { op: '*', fs: [x[1], x[3]] };
    });
    var orP = fmap(seq(token('('), formulaP, token('+'), formulaP, token(')')), function (x) {
      return { op: '+', fs: [x[1], x[3]] };
    });
    var impP = fmap(seq(token('('), formulaP, token('->'), formulaP, token(')')), function (x) {
      return { op: '->', fs: [x[1], x[3]] };
    });
    var notP = fmap(seq(token('-'), formulaP), function (x) {
      return { op: '-', fs: [x[1]] };
    });
    var valP = fmap(oneOf('abcdefghijkTF'), function (x) {
      return { val: x, fs: [] };
    });
    return choice(andP, orP, impP, notP, valP);
  });
  var equationP = fmap(seq(formulaP, token('='), formulaP), function (x) {
    return { left: x[0], right: x[2] };
  });

  var lines = stdin.toString().trim().split('\n');
  lines.pop();
  lines.forEach(function (s) {
    var r = equationP(s, 0);
    var isValid = true;

    var _loop = function _loop(i) {
      isValid &= evalF(r[1].left) === evalF(r[1].right);
      function toBool(c) {
        if (c === 'T') return true;
        if (c === 'F') return false;
        return !!(i >> c.charCodeAt() - 'a'.charCodeAt() & 1);
      }
      function evalF(f) {
        switch (f.fs.length) {
          case 0:
            return toBool(f.val);
          case 1:
            return !evalF(f.fs[0]);
          case 2:
            switch (f.op) {
              case '*':
                return evalF(f.fs[0]) && evalF(f.fs[1]);
              case '+':
                return evalF(f.fs[0]) || evalF(f.fs[1]);
              case '->':
                return !evalF(f.fs[0]) || evalF(f.fs[1]);
            }
        }
      }
    };

    for (var i = 0; i < 1 << 11; i++) {
      _loop(i);
    }
    console.log(isValid ? 'YES' : 'NO');
  });
})(require('fs').readFileSync('/dev/stdin', 'utf8'));