#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		int N;
		cin>>N;
		if(N == 0) break;
		int size = 0;
		ll res = 0;
		vector<string> s(N);
		map<char, ll> omomil;
		map<char, ll> omomir;
		int perm[10];
		vector<int> out;
		REP(i, 10) {
			perm[i] = (int)i;
		}
		REP(i, N) cin>>s[i];
		REP(i, N) {
			REP(j, s[i].size()) {
				if(omomil.count(s[i][s[i].size() - 1 - j]) == 0) {
					omomil[s[i][s[i].size() - 1 - j]] = 0;
					omomir[s[i][s[i].size() - 1 - j]] = 0;
					++size;
				}
				if(i != N - 1) omomil[s[i][s[i].size() - 1 - j]] += pow(10, j);
				else omomir[s[i][s[i].size() - 1 - j]] += pow(10, j);
			}
		}
		map<char, ll>::iterator ite3 = omomil.begin();
		int foo = 0;
		while(ite3 != omomil.end()) {
			REP(i, N) {
				if(s[i].size() > 1 && s[i][0] == (*ite3).first) {
					out.pb(foo);
					//cout<<(*ite3).first<<":"<<foo<<endl;
					break;
				}
			}
			++ite3;
			++foo;
		}

		ll sugoil[10];
		ll sugoir[10];
		ite3 = omomil.begin();
		REP(i, size) {
			sugoil[i] = (*ite3).second;
			++ite3;
		}
		ite3 = omomir.begin();
		REP(i, size) {
			sugoir[i] = (*ite3).second;
			++ite3;
		}
		do {
			ll l = 0;
			ll r = 0;
			bool cont = false;
			REP(i, out.size()) {
				if(perm[out[i]] == 0) {
					cont = true;
					break;
				}
			}
			if(cont) continue;
			REP(i, size) {
				l += perm[i] * sugoil[i];
				r += perm[i] * sugoir[i];
			}
			if(l == r) ++res;
		} while(next_permutation(perm, perm + 10));

		ll hoge = 1;
		REP(i, 10 - size) {
			hoge *= 10 - size - i;
		}
		cout<<res / hoge<<endl;
	}
}