### constant

MINUS = [[0] * 26 + [-1]]

### subroutines

def normalize(expr)
  return expr if expr.empty?

  expr.sort!
  term0 = expr.shift
  expr0 = []

  for term1 in expr
    if term0[0, 26] == term1[0, 26]
      term0[26] += term1[26]
    else
      expr0 << term0 if term0[26] != 0
      term0 = term1
    end
  end
  expr0 << term0 if term0[26] != 0

  expr0
end

def add_expr(expr0, expr1)
  #p ["add", expr0, expr1]
  expr = normalize(expr0 + expr1)
  #p ["add -> ", expr]
  expr
end

def mul_expr(expr0, expr1)
  #p ["mul", expr0, expr1]
  expr = []
  for term0 in expr0
    for term1 in expr1
      term = []
      (0...26).each{|i| term[i] = term0[i] + term1[i]}
      term[26] = term0[26] * term1[26]
      expr << term
    end
  end
  expr = normalize(expr)
  #p ["mul -> ", expr]
  expr
end

# <expr> := <term> ( ('+' | '-') <term>)*
# <term> := (<mult>)+
# <mult> := <num> | <var> ('^' <num>) | '(' <expr> ')'
# <num> := ('0'..'9')+
# <var> := 'a'..'z'

def skip_space(str)
  while str[$pos] == ' '
    $pos += 1
  end
end

def expr(str)
  skip_space(str)
  t0 = term(str)
  skip_space(str)

  while str[$pos] =~ /[\+\-]/
    op = str[$pos]
    $pos += 1

    skip_space(str)
    t1 = term(str)
    skip_space(str)

    t1 = mul_expr(t1, MINUS) if op == '-'
    t0 = add_expr(t0, t1)
  end

  t0
end

def term(str)
  skip_space(str)
  m0 = mult(str)
  skip_space(str)

  while str[$pos] =~ /[0-9a-z\(]/
    m1 = mult(str)
    skip_space(str)
    m0 = mul_expr(m0, m1)
  end

  m0
end

def mult(str)
  skip_space(str)

  m0 = [0] * 27

  case str[$pos]
  when '0'..'9'
    n = num(str)
    m0[26] = n
    return [m0]
  when 'a'..'z'
    v = str[$pos].ord - 'a'.ord
    $pos += 1
    skip_space(str)

    n = 1
    if str[$pos] == '^'
      $pos += 1
      skip_space(str)
      n = num(str)
      skip_space(str)
    end

    m0[v] = n
    m0[26] = 1
    return [m0]
  when '('
    $pos += 1
    skip_space(str)
    expr = expr(str)
    skip_space(str)
    $pos += 1
    return expr
  end
  nil
end

def num(str)
  n = 0
  while str[$pos] =~ /[0-9]/
    n = n * 10 + str[$pos].to_i
    $pos += 1
  end
  n
end

### main

loop do
  tstr = gets.strip
  break if tstr == '.'

  $pos = 0
  texpr = expr(tstr)
  #p [tstr, '=>' , texpr]

  loop do
    sstr = gets.strip
    break if sstr == '.'

    $pos = 0
    sexpr = expr(sstr)
    #p [sstr, '=>' , sexpr]

    puts (texpr == sexpr) ? 'yes' : 'no'
  end
  puts '.'
end