### subroutines

def ids2n(ids)
  ids.reverse.select{|id| id < 10}.map{|id| $ds[id]}.join('')
end

def print_expr
  estr = $expr.map{|ids| ids2n(ids)}.join('+') + '=' + ids2n($sexpr)
  puts estr
end

def count_rec(x, y, co = 0)
  if x >= $wsize
    #print_expr
    return (co == 0) ? 1 : 0
  end

  count = 0

  while y < $maxy && ! $ds[$expr[y][x]].nil?
    y += 1
  end

  if y < $maxy
    for d in (0..9)
      next if $used[d]

      id = $expr[y][x]
      next if d == 0 && $top[id]
      
      $used[d] = true
      $ds[id] = d
      count += count_rec(x, y + 1, co)
      $ds[id] = nil
      $used[d] = false
    end
  else
    sum = co
    (0...$maxy).each{|y0| sum += $ds[$expr[y0][x]]}
    d0 = sum % 10
    co0 = sum / 10

    id = $sexpr[x]
    if $ds[id].nil?
      if ! $used[d0] && (d0 != 0 || ! $top[id])
        $used[d0] = true
        $ds[id] = d0
        count += count_rec(x + 1, 0, co0)
        $ds[id] = nil
        $used[d0] = false
      end
    else
      if d0 == $ds[id]
        count += count_rec(x + 1, 0, co0)
      end
    end
  end

  count
end

### main

loop do
  n = gets.to_i
  break if n == 0

  words = n.times.map{gets.strip.split('').reverse}
  #puts words.map{|w| w.reverse.join('')}.join(' ')
  $wsize = words.map{|w| w.length}.max

  $expr = n.times.map{[]}
  $nch = 0
  chhash = {}
  
  for x in (0...$wsize)
    for y in (0...n)
      ch = words[y][x]
      if ch.nil?
        $expr[y][x] = 10
      else
        ci = chhash[ch]
        if ci.nil?
          $expr[y][x] = chhash[ch] = $nch
          $nch += 1
        else
          $expr[y][x] = chhash[ch]
        end
      end
    end
  end

  $top = (0..9).map{false}
  for y in (0...n)
    wlen = words[y].length
    if wlen > 1
      $top[$expr[y][wlen - 1]] = true
    end
  end
  
  $sexpr = $expr.pop
  $maxy = n - 1
  #p [$expr, $sexpr]
  #p $nch
  #p $top
  
  $ds = (0..9).map{nil} + [0]
  $used = (0..9).map{false} + [true]
  
  puts count_rec(0, 0)
end