
import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
import scala.io.StdIn._
object Main extends App {
  loop()
  @tailrec def loop(): Unit = {
    readLine.trim match {
      case "#" ⇒ return
      case Equation(e) ⇒
        println(if (e.isIdentify) "YES" else "NO")
        loop()
      case _ ⇒ ???
    }
  }
}

object Equation {
  def unapply(arg: String): Option[(Equation)] = {
    arg.toList match {
      case (l Formula '='::(r Formula Nil)) ⇒ Some(new Equation(l, r, arg.filter(_.isLower).map(c ⇒ (1 << (c - 'a'))).reduce(_ | _)))
      case _ ⇒ None
    }
  }
}
class Equation(left: Formula, right: Formula, variables: Int) {
  val isIdentify: Boolean = (0 until (1 << 11)).filter(s ⇒ (s & ~variables) == 0).forall(state ⇒ left(state) == right(state))
}
object Formula {
  def unapply(arg: List[Char]): Option[(Formula, List[Char])] = {
    arg match {
      case t True r ⇒ Some(t, r)
      case f False r ⇒ Some(f, r)
      case v Variable r ⇒ Some(v, r)
      case n Neg r ⇒ Some(n, r)
      case b BiOperator r ⇒ Some(b, r)
      case _ ⇒ None
    }
  }
  object True extends Formula {
    def unapply(arg: List[Char]): Option[(True.type, List[Char])] = {
      arg match {
        case 'T'::r ⇒ Some(this, r)
        case _ ⇒ None
      }
    }
    override def apply(state: Int): Boolean = true
  }
  object False extends Formula {
    def unapply(arg: List[Char]): Option[(False.type, List[Char])] = {
      arg match {
        case 'F'::r ⇒ Some(this, r)
        case _ ⇒ None
      }
    }
    override def apply(state: Int): Boolean = false
  }
  object Neg {
    def unapply(arg: List[Char]): Option[(Neg, List[Char])] = {
      arg match {
        case '-'::(f Formula r) ⇒Some(new Neg(f), r)
        case _ ⇒ None
      }
    }
  }
  class Neg(formula: Formula) extends Formula {
    override def apply(state: Int): Boolean = !formula(state)
  }
  object BiOperator {
    def unapply(arg: List[Char]): Option[(BiOperator, List[Char])] = {
      arg match {
        case '('::(l Formula rest) ⇒
          rest match {
            case '+'::(r Formula ')'::ex) ⇒ Some(new Or(l, r), ex)
            case '*'::(r Formula ')'::ex) ⇒Some(new And(l, r), ex)
            case '-'::'>'::(r Formula ')'::ex) ⇒ Some(new :->(l, r), ex)
            case _ ⇒ None
          }
      }
    }
  }
  sealed trait BiOperator extends Formula
  class Or(left: Formula, right: Formula) extends BiOperator {
    override def apply(state: Int): Boolean = left(state) || right(state)
  }
  class And(left: Formula, right: Formula) extends BiOperator {
    override def apply(state: Int): Boolean = left(state) && right(state)
  }
  class :->(left: Formula, right: Formula) extends BiOperator {
    override def apply(state: Int): Boolean = !left(state) || right(state)
  }
  object Variable {
    def unapply(arg: List[Char]): Option[(Variable, List[Char])] = {
      arg match {
        case letter::r if letter.isLower ⇒ Some(new Variable(letter), r)
        case _ ⇒ None
      }
    }
  }
  class Variable(letter: Char) extends Formula {
    override def apply(state: Int): Boolean = ((1 << (letter - 'a')) & state) != 0
  }
}
sealed trait Formula {
  def apply(state: Int): Boolean
}

