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

#define N 12
#define L 8
#define TRUE 1
#define FALSE 0

int n;
int cnum;
char m[N][L];
char f[128];
char vc[11];
int used[10];
int mlen[N];
int non_zero[128];

int dfs(int depth){
  int i,j;
  int ret = 0;
  if(depth==cnum){
    char tm[N][L];
    for(i = 0; i < n; ++i){
      for(j = 0; j < mlen[i]; ++j){
	tm[i][j] = f[ m[i][j] ];
      }
    }
    int sum=0;
    for(i = 0; i < n; ++i){
      char v[mlen[i]+1];
      for(j = 0; j < mlen[i]; ++j){
	v[j] = tm[i][j];
      }
      v[mlen[i]]=0;
      if(i==n-1){
	if(sum==atoi(v)){
	  return 1;
	}
	else return 0;
      }
      sum+=atoi(v);
    }
  }
  for(i = 0; i < 10; ++i){
    if( !used[i] ){
      used[i]=TRUE;
      f[vc[depth]]=i+'0';
      if(i==0&&non_zero[vc[depth]] )goto NEXT;
      ret += dfs(depth+1);
    NEXT:;
      used[i]=FALSE;
    }
  }
  return ret;
}

int main()
{
  int i,j,k;
  while(TRUE){
    int ans = 0;

    scanf("%d",&n);
    if(n==0)break;

    cnum = 0;
    for(i = 0; i <128;++i){
      f[i]=0;
      non_zero[i]=FALSE;
    }
    for(i = 0; i < 10; ++i){
      used[i] = FALSE;
      vc[i]=0;
    }
    vc[10]=0;
    for(i = 0; i < N; ++i){
      mlen[i]=0;
      for(j = 0; j < L; ++j){
	m[i][j] = '0';
      }
    }

    for(i = 0; i < n; ++i){
      char buf[128];
      scanf("%s",buf);
      mlen[i]=strlen(buf);
      int len = strlen(buf);
      for(j = 0; j < len; ++j){
	m[i][j] = buf[j];
	f[m[i][j]]='0';
	int bFound=FALSE;
	for(k = 0; k < cnum; ++k){
	  if(vc[k]==m[i][j]){bFound=TRUE;break;}
	}
	if(!bFound)vc[cnum++]=m[i][j];
	if(j==0&&len>1)non_zero[buf[j]]=TRUE;
      }
    }

    ans = dfs(0);
    printf("%d\n",ans);
  }
  return 0;
}