#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;


int main(void) {

    int n;
    while(cin >> n, n){
        vs s(n);
        rep(i,n) cin >> s[i];

        int co[26] = {};
        int c[26] = {};//leading zeros
        rep(i,n){
            if(s[i].size()>1)c[s[i][0]-'A']++;
            int t[26] = {};
            rep(j,s[i].size()){
                rep(k,26)t[k]*=10;
                t[s[i][j]-'A']++;
            }
            if(i+1<n)rep(j,26)co[j] += t[j];
            else rep(j,26)co[j] -= t[j];
        }
        int a[26] = {};
        rep(i,n)rep(j,s[i].size())a[s[i][j] - 'A']++;

        vi v;
        rep(i,26)if(a[i])v.push_back(i);

        while(v.size()<10)v.push_back(-1);
        sort(all(v));
        int ans = 0;

        do{
            int alph[26];
            rep(i,26) alph[i] = -1;
            rep(i,v.size())if(v[i] >= 0)alph[v[i]]=i;

            if(v[0] >= 0 && c[v[0]])continue;

            int sum = 0;
            rep(i,26)if(alph[i]>=0){
                sum += co[i] * alph[i];
            }

            if(sum == 0){
                ans++;
            }
        }while(next_permutation(all(v)));

        cout << ans << endl;

    }
}

