#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

bool n_zero[10], f[10];
int coe[10], cnt, c;

void dfs(int n, int s) {
  if (n == cnt) {
    if (!s) c++;
    return;
  }

  rep(i,10){
    if (f[i] || (!i && n_zero[n])) continue;

    f[i] = 1;
    dfs(n + 1, s + i * coe[n]);
    f[i] = 0;
  }

}

int main(){  
  int n;

  while (cin >> n, n) {
    string str;
    vector<int> index(26, -1);
    cnt=0,c=0;
   

    fill_n((bool*) n_zero,sizeof(n_zero)/sizeof(bool),0);
    fill_n((bool*) coe,sizeof(coe)/sizeof(bool),0);
    fill_n((bool*) f,sizeof(f)/sizeof(bool),0);


    rep(i,n){
      cin >> str;

      rep(j,str.size()){  
        int ch = str[j] - 'A';
        if (index[ch] == -1) {
          index[ch] = cnt; cnt++;
        }

        if (str.size() > 1 && !j) n_zero[index[ch]] = 1;

        if (i != n - 1) coe[index[ch]] += pow(10, str.size() - 1 - j);
        else coe[index[ch]] -= pow(10, str.size() - 1 - j);
      }
    }

    dfs(0, 0);

    cout << c << endl;
  }

  return 0;
}