#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

vector<char> alpha;
int coef[28];
bool nonzero[28], used[10];

int solve(int idx, int sum)
{
  if(idx == alpha.size()) return sum == 0;
  
  int ret = 0, c = alpha[idx] - 'A';
  for(int i = 0; i < 10; i++) {
    if(used[i]) continue;
    if(i == 0 && nonzero[c]) continue;
    used[i] = true;
    ret += solve(idx + 1, sum + coef[c]*i);
    used[i] = false;
  }
  return ret;
}

int main()
{
  int N;
  while(cin >> N, N) {
    
    alpha.clear();
    fill(coef, coef + 28, 0);    
    fill(nonzero, nonzero + 28, false);
    fill(used, used + 10, false);
    
    for(int i = 0; i < N; i++) {
      string item; cin >> item;
      
      if(item.size() != 1) nonzero[item[0]-'A'] = true;
      reverse(all(item));
      
      int mul = 1;
      for(char a : item) {
	alpha.push_back(a);
	coef[a-'A'] += (i == N-1 ? -mul : mul);
	mul *= 10;
      }
    }
    
    sort(all(alpha));
    alpha.erase(unique(all(alpha)), alpha.end());
    
    cout << solve(0, 0) << endl;
  }
  return 0;
}