#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);
#define readV(_v) rep(j, _v.size()) cin >> _v[j];
#define readVV(_vv) rep(i, _vv.size()) readV(_vv[i]);
#define output(_x) cout << _x << endl;

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

int fact(int x) {
    if (x == 0) return 1;
    return x * fact(x - 1);
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n;
    while (cin >> n, n) {
        vector<string> s(n);
        rep(i, n) cin >> s[i];

        map<char, int> mp;
        rep(i, n) {
            for (auto c : s[i]) {
                mp[c] = 0;
            }
        }

        int kind = 0;
        for (auto& p : mp) {
            p.second = kind++;
        }

        vector<bool> nonZero(kind);
        rep(i, n) {
            if (s[i].size() > 1) nonZero[mp[s[i][0]]] = true;
        }

        vi coef(kind);
        rep(i, n) {
            rep(j, s[i].size()) {
                coef[mp[s[i][j]]] += (i == n - 1 ? -1 : +1) * pow(10, (int)s[i].size() - j - 1);
            }
        }

        int ans = 0;
        vi perm(10); // kind to digit
        iota(all(perm), 0);
        do {
            int t = 0;
            bool flag = true;
            rep(i, kind) {
                if (nonZero[i] && perm[i] == 0) {
                    flag = false;
                    break;
                }
                t += coef[i] * perm[i];
            }
            if (flag && t == 0) {
                ans++;
            }
        } while (next_permutation(all(perm)));

        cout << ans / fact(10 - kind) << endl;
    }
}