
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAX_N = 17;
const int MAX_LEN = 10;
int N, M;

char buf[MAX_N][MAX_LEN];
vector<int> pats[MAX_N];
int lens[MAX_N];
bool isTop[10];
int num[10];
int coef[10];

void init(){
	vector<char> cs;
	for(int i=0; i<N; i++){
		lens[i] = strlen(buf[i]);
		for(int j=0; j<lens[i]; j++){
			cs.push_back(buf[i][j]);
		}
	}
	sort(cs.begin(), cs.end());
	cs.erase(unique(cs.begin(), cs.end()), cs.end());
	M = cs.size();
	for(int i=0; i<N; i++){
		for(int j=0; j<lens[i]; j++){
			for(int k=0; k<M; k++)if(cs[k]==buf[i][j]){
				pats[i].push_back(k);
			}
		}
	}
	for(int i=0; i<M; i++)  isTop[i] = false;
	for(int i=0; i<M; i++)  coef[i] = 0;
	for(int i=0; i<N; i++){
		int base = 1;
		for(int j=lens[i]-1; j>=0; j--){
			coef[pats[i][j]] += (i==N-1?-base:base);
			base *= 10;
			if(j==0 && lens[i]>1){
				isTop[pats[i][j]] = true;
			}
		}
	}
}

bool check(){
	int tot = 0;
	for(int i=0; i<M; i++){
		if(isTop[i] && !num[i]) return false;
	}
	for(int i=0; i<M; i++){
		tot += num[i]*coef[i];
	}
	return tot==0;
}

int solve(){
	init();
	int ans = 0;
	int bit = (1<<M)-1;
	while(bit < (1<<10)){
		int p=0;
		for(int i=0; i<10; i++)if((bit>>i)&1){
			num[p++] = i;
		}
		do{
			if(check()){
				ans++;
			}
		}while(next_permutation(num, num+M));
		int x = bit & -bit, y = bit + x;
		bit = ((bit & ~y) / x >> 1) | y;
	}
	return ans;
}

int main(){
	while(scanf("%d",&N),N){
		for(int i=0; i<N; i++){
			scanf(" %[^\n]", buf+i);
			pats[i].clear();
		}
		printf("%d\n",solve());
	}
	return 0;
}