while line = gets
    line = line.chomp.split('+')
    line[1, 2] = line[1].split('=')
    line.map!{|item| item.reverse}
    start = line.any?{|item| item.end_with?('X')} ? 1 : 0
    match = false
    start.upto(9){|x|
        item = [0, 0, 0]
        line.each_with_index{|y, i|
            y.split('').each_with_index{|c, keta|
                case c
                when 'X'
                    item[i] += (x * (10 ** keta))
                else
                    item[i] += (c.to_i * (10 ** keta))
                end
            }
        }
        if item[0] + item[1] == item[2]
            match = x
            break
        end
    }
    puts match ? match : "NA"
end

