#include <stdio.h>
#include <string.h>
#include <math.h>

#define REP(i,n,m) for(i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

int usedDigit[10]; //0~9ÌàÇÌðgÁ½©ÌtO
int w[26]; //¶ÌdÝ
int initFlg[26]; //ª¶ÉÊu·é©Ç¤©ÌtO
int ap[26]; //¶ªüÍ³ê½©Ç¤©ÌtO
int seq[26];

int calRem(int idx){
	int i,j;
	int start,res = 0;

	REP(i,idx,26) if(ap[i] && w[i]==0) break;
	if(i == 26) return 1;
	start = initFlg[i];

	REP(j,start,10){
		if(!usedDigit[j]){
			usedDigit[j] = 1;
			res += calRem(i+1);
			usedDigit[j] = 0;
		}
	}

	return res;
}

int solve(int rem,int sum,int idx){
	int i,j;
	int start,res = 0;

	if(rem == 0){
		if(sum == 0) return calRem(0);
		return 0;
	}

	REP(i,idx,26) if(w[i] != 0) break;
	start = initFlg[i];

	REP(j,start,10){
		if(!usedDigit[j]){
			usedDigit[j] = 1;
			res += solve(rem-1,sum+w[i]*j,i+1);
			usedDigit[j] = 0;
		}
	}

	return res;
}

int main(void){
	int i,j;
	int n,m; //¶ñÌ,At@xbgÌíÞ
	int len;
	char s[12];

	while(scanf("%d",&n) && n){
		rep(i,26) w[i] = initFlg[i] = ap[i] = 0;
		rep(i,10) usedDigit[i] = 0;

		rep(i,n){
			scanf("%s",s);
			len = strlen(s);
			if(len != 1) initFlg[s[0]-'A'] = 1;
			rep(j,len){
				ap[s[j]-'A'] = 1;
				if(i == n-1) w[s[j]-'A'] -= pow(10,len-j-1);
				else w[s[j]-'A'] += pow(10,len-j-1);
			}
		}

		m = 0;
		rep(i,26) if(w[i] != 0) m++;
		printf("%d\n",solve(m,0,0));
	}

	return 0;
}