#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
string S[20];
int mem[256];
bool used[10];

int solve(int x,int y,int t){
    if(x==8){
        return t==0;
    }

    if(y==N){
        if(t<0||t%10)return false;
        return solve(x+1,0,t/10);
    }

    if(S[y].size()<=x)return solve(x,y+1,t);

    int ret=0;
    for(int i=0;i<10;i++){
        if(S[y].size()>1&&x+1==S[y].size()&&i==0)continue;
        if(mem[S[y][x]]!=-1){
            if(mem[S[y][x]]!=i)continue;
            ret+=solve(x,y+1,t+i*(y==N-1?-1:1));
        }
        else if(!used[i]){
            mem[S[y][x]]=i;used[i]=1;
            ret+=solve(x,y+1,t+i*(y==N-1?-1:1));
            mem[S[y][x]]=-1;used[i]=0;
        }
    }
    return ret;
}

signed main(){
    memset(mem,-1,sizeof(mem));
    while(cin>>N,N){
        rep(i,N)cin>>S[i];
        rep(i,N)reverse(all(S[i]));
        cout<<solve(0,0,0)<<endl;
    }
    return 0;
}