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

int answer;
int zero[10];
char alp[11],siki[9][9];

void check(int *data,int n,int p){
  int i,j,k,num,tmp;

  num = 0;

  for(i = 0;i < n;i++){
    tmp = 0;
    for(j = 0;siki[i][j] != '\0';j++){
      tmp *= 10;
      for(k = 0;k < p;k++){
	if(alp[k] == siki[i][j]){
	  tmp += data[k];
	}
      }
    }
    
    //printf("%d\n",tmp);

    if(i == (n-1)){
      if(num == tmp){
	answer++;
      }
    }else{
      num += tmp;
    }
  }
}

void output(int *data,int p){
  int i;

  for(i = 0;i < p;i++){
    printf("%d ",data[i]);
  }
  printf("\n");
}

void foo(int *data,int *flag,int n,int m,int p){
  int i;

  if(m == p){
    check(data,n,p);
    //output(data,p);
  }else{
    for(i = 0;i < 10;i++){
      if(!flag[i]){
	if(i == 0){
	  if(!zero[m]){
	    data[m] = 0;
	    flag[0] = 1;
	    foo(data,flag,n,m+1,p);
	    flag[0] = 0;
	  }
	}else{
	  data[m] = i;
	  flag[i] = 1;
	  foo(data,flag,n,m+1,p);
	  flag[i] = 0;
	}
      }
    }
  }
}

int main(){
  int n,i,j,k,p,f;
  int data[10],flag[10];
  char str[9];

  while(1){
    scanf("%d",&n);
    if(n == 0){
      break;
    }

    memset(data,0,sizeof(data));
    memset(flag,0,sizeof(flag));
    memset(zero,0,sizeof(zero));
    memset(alp,'\0',sizeof(alp));
    p = 0;
    answer = 0;

    for(i = 0;i < n;i++){
      scanf("%s",str);
      for(j = 0;str[j] != '\0';j++){
	f = 0;
	for(k = 0;k < p;k++){
	  if(alp[k] == str[j]){
	    f = 1;
	    if(str[1] != '\0' && j == 0){
	      zero[k] = 1;
	    }
	    break;
	  }
	}
	if(!f){
	  alp[p] = str[j];
	  if(str[1] != '\0' && j == 0){
	    zero[p] = 1;
	  }
	  p++;
	}
      }
      strcpy(siki[i],str);
    }

    foo(data,flag,n,0,p);

    printf("%d\n",answer);
  }

  return 0;
}