-- alphametic '5' ??"123","4X6","X79"?? == True
alphametic :: Char -> ??String?? -> Bool
alphametic x ts = a + b == c && satisfiesPrefixRule x ts
  where ??a,b,c?? = map (read . map (replaceX x)) ts

satisfiesPrefixRule x = and . map (prefixRule x)
  where prefixRule x t = not (x == '0' && head t == 'X' && t /= "X")

replaceX x t ?? t == 'X'  = x
             ?? otherwise = t

main = do
  s <- getContents
  putStr . unlines . map eachLine . lines $ s

eachLine l = showResult $ filter (`alphametic` ts) ??'0'..'9'??
  where
    ts = words . map opToSpace $ l

showResult ???? = "NA"
showResult (x:xs) = ??x??

opToSpace '+' = ' '
opToSpace '=' = ' '
opToSpace  c  =  c