 
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

string cmp(string a,string b){
    if(a.size()==b.size())return a<b?b:a;
    else return a.size()<b.size()?b:a;
}

int main(){
	int n;
	vi d={0,362880,40320,5040,720,120,24,6,2,1,1,};
	while(cin>>n,n){
        vs s(n);
        map<char,int> mp;
        set<char> st;
        rep(i,n) {
            cin>>s[i];
            if(s[i].size()!=1)st.insert(s[i][0]);
            int d=1,pref=(i+1==n)?-1:1;
            for(int j=s[i].size()-1;j>=0;j--){
                if(mp.find(s[i][j])==mp.end()){
                    mp[s[i][j]]=0;
                }
                mp[s[i][j]]+=pref*d;
                d*=10;
            }
        }
        string c="";
        vlai x(0,10);
        int lp=0;
        for(auto p:mp){
            c+=p.fs; x[lp++]=p.sc;
        }
        vlai p(10); iota(begin(p),end(p),0);
        
        int ans=0;
        do{
            //ans+=(p*x).sum()==0;
            if(st.find(c[find(begin(p),end(p),0)-begin(p)])!=st.end()) continue;
            if((p*x).sum()==0){
                ans++;
                //cout<<c[find(begin(p),end(p),0)-begin(p)];rep(i,10)cout<<p[i];cout<<endl;
            }
        }while(next_permutation(begin(p),end(p)));
        cout<<ans/d[mp.size()]<<endl;
	}
	return 0;
}

