import scala.annotation.tailrec
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {

  solve()
  @tailrec def solve(): Unit = {
    val expected = readLine.trim.toList match {
      case e Equals _ ⇒ e
      case '.'::_ ⇒ return
    }
    equals(expected)
    println(".")
    solve()
  }
  @tailrec def equals(expected: Expression): Unit = {
    val candidate = readLine.trim.toList match {
      case e Equals _ ⇒ e
      case '.'::_ ⇒ return
    }
    println(if (candidate == expected) "yes" else "no")
    equals(expected)
  }

}
case class Expression(val map: Map[List[Char], Long]) {
  def *(that: Expression): Expression = {
    val result = mutable.Map[List[Char], Long]().withDefaultValue(0L)
    for ((key, value) ← map) {
      for ((k, v) ← that.map) {
        result((k ++ key).sorted) += value * v
      }
    }
    Expression(result.toMap.filterNot(_._2 == 0))
  }
  def +(that: Expression): Expression = {
    val result = mutable.Map[List[Char], Long]().withDefaultValue(0L)
    for ((key, value) ← map) {
      result(key) += value
    }
    for ((key, value) ← that.map) {
      result(key) += value
    }
    Expression(result.toMap.filterNot(_._2 == 0))
  }
  def -(that: Expression): Expression = {
    val result = mutable.Map[List[Char], Long]().withDefaultValue(0L)
    for ((key, value) ← map) {
      result(key) += value
    }
    for ((key, value) ← that.map) {
      result(key) -= value
    }
    Expression(result.toMap.filterNot(_._2 == 0))
  }
  def power(exp: Long): Expression = {
    exp match {
      case 0L ⇒ Expression(Map(Nil → 1L))
      case 1L ⇒ this
      case _ ⇒ power(exp & 1L) * (this * this).power(exp >> 1)
    }
  }

  override def equals(obj: Any): Boolean = {
    obj match {
      case that: Expression ⇒ map.count(_._2 != 0) == that.map.count(_._2 != 0) && map.forall{case (k, v) ⇒ that.map.getOrElse(k, 0) == v}
      case _ ⇒ super.equals(obj)
    }
  }
}

object Equals {
  def unapply(arg: List[Char]): Option[(Expression, List[Char])] = {
    arg.dropWhile(_.isWhitespace) match {
      case f Factor r ⇒ Some(express(f, r))
      case _ ⇒ None
    }
  }
  @tailrec private def express(left: Expression, arg: List[Char]): (Expression, List[Char]) = {
    arg.dropWhile(_.isWhitespace) match {
      case '+'::(right Factor r) ⇒ express(left + right, r)
      case '-'::(right Factor r) ⇒ express(left - right, r)
      case _ ⇒ (left, arg)
    }
  }
  object Number {
    def unapply(arg: List[Char]): Option[(Long, List[Char])] = {
      arg.dropWhile(_.isWhitespace).span(_.isDigit) match {
        case (Nil, _) ⇒ None
        case (n, r) ⇒ Some( n.foldLeft(0L){case (acc, v) ⇒ acc * 10 + v.asDigit}, r)
      }
    }
  }
  object Factor {
    def unapply(arg: List[Char]): Option[(Expression, List[Char])] = {
      arg.dropWhile(_.isWhitespace) match {
        case t Term r ⇒ Some(takeAll(t, r))
        case _ ⇒ None
      }
    }
    @tailrec private def takeAll(left: Expression, arg: List[Char]): (Expression, List[Char]) = {
      arg.dropWhile(_.isWhitespace) match {
        case right Term rest ⇒ takeAll(left * right, rest)
        case _ ⇒ (left, arg)
      }
    }
  }
  object Term {
    def unapply(arg: List[Char]): Option[(Expression, List[Char])] = {
      arg.dropWhile(_.isWhitespace) match {
        case n Number r ⇒Some(takeExp(Expression(Map(Nil → n)), r))
        case '(':: (e Equals rest) ⇒
          rest.dropWhile(_.isWhitespace) match {
            case ')'::r ⇒ Some(takeExp (e, r) )
            case _ ⇒ ???
          }
        case c::r if c.isLetter ⇒ Some(takeExp(Expression(Map(List(c) → 1L)), r))
        case _ ⇒ None
      }
    }
    private def takeExp(left: Expression, arg: List[Char]): (Expression, List[Char]) = {
      arg.dropWhile(_.isWhitespace) match {
        case '^'::(n Number r) ⇒ (left.power(n), r)
        case _ ⇒ (left, arg)
      }
    }
  }
}





Measured memory_bytes: 421948