//AC記録用コピペ
//自分のコードは1テストケースファイルあたり10分程度
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3566759#1
#include <bits/stdc++.h>
using namespace std;
  
int N, Size;
string s[12];
  
  
int rec(int idx, int md, int sum, int used, vector< int >& conb) // ??´???, ??°????????????, ?????£?????°???
{
    for(int i = 0; i < N; i++) if(s[i].size() != 1 && conb[s[i][s[i].size() - 1]] == 0) return(0);
    if(idx == s[N - 1].size()) return(sum == 0);
      
    int ret = 0;
      
    for(int i = md; i < N - 1; i++) {
        if(s[i].size() <= idx) continue;
        if(conb[s[i][idx]] != -1) {
            sum += conb[s[i][idx]];
        } else {
            for(int j = 0; j < 10; j++) {
                if((used >> j) & 1) continue;
                conb[s[i][idx]] = j;
                ret += rec(idx, i + 1, sum + j, used|(1 << j), conb);
                conb[s[i][idx]] = -1;
            }
            return(ret);
              
        }
    }
      
    int digit = sum % 10;
      
    if(conb[s[N - 1][idx]] == -1) {
        if((used >> digit) & 1) return(0);
          
        conb[s[N - 1][idx]] = digit;
        ret = rec(idx + 1, 0, sum / 10, used|(1 << digit), conb);
        conb[s[N - 1][idx]] = -1;
          
    } else {
      
        if(digit != conb[s[N - 1][idx]]) return(0);
        ret = rec(idx + 1, 0, sum / 10, used, conb);
          
    }
    return(ret);
}
  
int main()
{
    while(cin >> N, N) {
        Size = 0;
        for(int i = 0; i < N; i++) {
            cin >> s[i];
            reverse(s[i].begin(), s[i].end());
            if(i != N - 1) Size = max< int >(Size, s[i].size());
        }
        vector< int > conb(128, -1);
        if(Size > s[N - 1].size()) cout << 0 << endl;
        else cout << rec(0, 0, 0, 0, conb) << endl;
    }
}
