$h = Hash.new
def parse(s,env)
    if $h.has_key?(s)
        return $h[s]
    end
    case s[0]
    when "T"
        return 1
    when "F"
        return 0
    when "a"
        return env[0]
    when "b"
        return env[1]
    when "c"
        return env[2]
    when "d"
        return env[3]
    when "e"
        return env[4]
    when "f"
        return env[5]
    when "g"
        return env[6]
    when "h"
        return env[7]
    when "i"
        return env[8]
    when "j"
        return env[9]
    when "k"
        return env[10]
    when "-"
        ret = 1 - parse(s[1...s.length],env)
        $h[s] = ret
        return ret
    when "("
        index = 1
        level = 0
        while index < s.length
            if s[index] == "("
                level += 1
            elsif s[index] == ")"
                level -= 1
            elsif s[index] == "*" && level == 0
                a = parse(s[1...index],env)
                b = parse(s[(index+1)...s.length],env)
                if a == 0 || b == 0
                    $h[s] = 0
                    return 0
                else
                    $h[s] = 1
                    return 1
                end
            elsif s[index] == "+" && level == 0
                a = parse(s[1...index],env)
                b = parse(s[(index+1)...s.length],env)
                if a == 0 && b == 0
                    $h[s] = 0
                    return 0
                else
                    $h[s] = 1
                    return 1
                end
            elsif s[index] == "-" && s[index+1] == ">" && level == 0
                a = parse(s[1...index],env)
                b = parse(s[(index+2)...s.length],env)
                if a == 1 && b == 0
                    $h[s] = 0
                    return 0
                else
                    $h[s] = 1
                    return 1
                end
            end
            index += 1
        end
        return -1
    end
end
loop do
    s = gets.chomp.gsub("--","")
    break if s == "\#"
    count = 0
    [0,1].repeated_permutation(11).each do |env|
        $h = Hash.new
        a, b = s.split("=")
        count += 1 if parse(a,env) == parse(b,env)
    end
    puts count == 2**11 ? "YES" : "NO"
end