//=================================
// Created on: 2018/07/04 15:12:12
//=================================
#include <bits/stdc++.h>
using namespace std;
int main()
{
    for (int N;;) {
        cin >> N;
        if (N == 0) { break; }
        vector<int> coeff1(10, 0);
        vector<int> coeff2(10, 0);
        set<int> nz;
        map<char, int> ind;
        for (int i = 0; i < N; i++) {
            string s;
            cin >> s;
            reverse(s.begin(), s.end());
            for (int j = 0, d = 1; j < s.size(); j++, d *= 10) {
                const char c = s[j];
                if (ind.find(c) == ind.end()) {
                    const int s = ind.size();
                    ind[c] = s;
                }
                const int in = ind[c];
                (i < N - 1 ? coeff1 : coeff2)[in] += d;
                if (j == s.size() - 1 and s.size() > 1) { nz.insert(in); }
            }
        }
        vector<int> num{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        int div = 1;
        for (int i = 0; i < 10 - (int)ind.size(); i++) { div *= (i + 1); }
        int ans = 0;
        do {
            bool ok = true;
            for (const int nzz : nz) {
                if (num[nzz] == 0) {
                    ok = false;
                    break;
                }
            }
            if (not ok) { continue; }
            int left = 0, right = 0;
            for (int i = 0; i < ind.size(); i++) { left += coeff1[i] * num[i], right += coeff2[i] * num[i]; }
            if (left == right) { ans++; }
        } while (next_permutation(num.begin(), num.end()));
        cout << ans / div << endl;
    }
    return 0;
}

