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

char alphabet[10];
int suffix[10],num[10];
char string[12][9];
int length[12];
int number[12];
int usenum[10];
int ans,c,n;

void verbal(int x){
  int i,j,k;
  int sum;

  if(x==c){
    for(i=0;i<n;i++){
      number[i] = 0;
      for(j=0;j<length[i];j++){
	for(k=0;k<c;k++){
	  if(string[i][j] == alphabet[k]){
	    number[i] += pow(10, (length[i] - j - 1) ) * num[k];
	  }
	}
      }
    }
    sum = 0;
    for(i=0;i<n-1;i++)sum += number[i];
    if(number[n-1]==sum)ans++;
  }else{
    for(j=0;j<10;j++){
      if(!usenum[j]){
	if(j || !suffix[x]){
	  usenum[j] = 1;
	  num[x] = j;
	  verbal(x+1);
	  usenum[j] = 0;
	}
      }
    }
  }
}

int main(void)
{

  int i,j,k;
  int flag;

  while(1){
    scanf("%d",&n);
    if(!n)break;

    for(i=0;i<n;i++){
      scanf("%s ",string[i]);
      length[i] = strlen(string[i]);
      number[i] = 0;
    }

    c = 0;
    for(i=0;i<n;i++){
      for(j=0;j<length[i];j++){
	if(c==0){
	  alphabet[c] = string[i][j];
	  if(length[i]>1)suffix[c] = 1;
	  else suffix[i] = 0;
	  c++;
	}else{
	  flag = 1;
	  for(k=0;k<c;k++){
	    if(alphabet[k] == string[i][j]){
	      if(!j && length[i]>1)suffix[k] = 1;
	      else suffix[i] = 0;
	      flag = 0;
	      break;
	    }
	  }
	  if(flag){
	    alphabet[c] = string[i][j];
	    if(!j && length[i]>1)suffix[c] = 1;
	    else suffix[c] = 0;
	    c++;
	  }
	}
      }
    }

    ans = 0;
    for(i=0;i<c;i++)usenum[i] = 0;

    /*for(i=0;i<c;i++)printf("%c ",alphabet[i]);
    putchar('\n');
    for(i=0;i<c;i++)printf("%d ",suffix[i]);
    putchar('\n');*/


    verbal(0);
    printf("%d\n",ans);

  }
  return 0;
}