#include <bits/stdc++.h>
using namespace std;

int it;
map<char, int> dic;

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	while (cin >> N, N) {
		it = 0;
		dic.clear();
		vector<bool> flag(10);
		vector<vector<int>> val(N);
		for (int i = 0; i < N; i++) {
			string s;
			cin >> s;
			for (auto c : s) {
				val[i].push_back(dic.count(c) ? dic[c] : dic[c] = it++);
			}
			if ((int)s.size() != 1) flag[val[i][0]] = true;
		}
		vector<int> d(10);
		for (int i = 0; i < 10; i++) d[i] = i;
		int res = 0;
		do {
			int zer = find(d.begin(), d.end(), 0) - d.begin();
			if (flag[zer]) continue;
			int sum = 0;
			for (int i = 0; i < N; i++) {
				int x = 0;
				for (auto v : val[i]) {
					x = x * 10 + d[v];
				}
				sum += i + 1 == N ? -x : x;
			}
			if (sum == 0) res++;
		} while (next_permutation(d.begin(), d.end()));
		for (int i = 1; i <= 10 - it; i++) res /= i;
		cout << res << endl;
	}
	return 0;
}

