#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 m;
int usedAlpha[26],usedDigit[10]; //0~9ÌàÇÌðgÁ½©ÌtO
int w[26],tw[26]; //¶ÌdÝ
int initFlg[26],tinitFlg[26]; //ª¶ÉÊu·é©Ç¤©ÌtO
int ap[26]; //¶ªüÍ³ê½©Ç¤©ÌtO


int solve(int rem,int sum){
	if(rem == 0) return sum == 0;

	//printf("%d %d\n",rem,sum);

	int i,j;
	int start,res = 0;

	rep(i,m) if(!usedAlpha[i] && (sum == 0 || sum>0 && w[i]<=0 || sum<0 && w[i]>=0)){
		usedAlpha[i] = 1;
		start = initFlg[i];
		REP(j,start,10) if(!usedDigit[j]){
			usedDigit[j] = 1;
			res += solve(rem-1,sum+w[i]*j);
			usedDigit[j] = 0;
		}
		//usedAlpha[i] = 0;
	}

	return res;
}

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

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

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

		m = 0;
		rep(i,26){
			if(tw[i] != 0 || tw[i] == 0 && ap[i]){
				w[m] = tw[i];
				initFlg[m++] = tinitFlg[i];
			}
		}

		rep(i,m-1) REP(j,i+1,m) {
			if(abs(w[i]) < abs(w[j])){
				w[i] ^= w[j];
				w[j] ^= w[i];
				w[i] ^= w[j];
				initFlg[i] ^= initFlg[j];
				initFlg[j] ^= initFlg[i];
				initFlg[i] ^= initFlg[j];
			}
		}

		printf("%d\n",solve(m,0));
	}

	return 0;
}