#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int n, cnt, a[13][9], l[13], x[11], used[11], zero[11], power[9]; char c[11];
int solve(int depth, int value) {
	if (depth == cnt) return value ? 0 : 1;
	int ret = 0;
	for (int i = 0; i < 10; i++) {
		if (!used[i]) {
			used[i] = 1;
			if(i || zero[depth]) ret += solve(depth + 1, value + x[depth] * i);
			used[i] = 0;
		}
	}
	return ret;
}
int main() {
	string s; power[0] = 1;
	for (int i = 1; i < 9; i++) power[i] = power[i - 1] * 10;
	while (cin >> n, n) {
		cnt = 0;
		for (int i = 0; i < 10; i++) zero[i] = 1, x[i] = c[i] = 0;
		for (int i = 0; i < n; i++) {
			cin >> s; l[i] = s.size();
			reverse(s.begin(), s.end());
			for (int j = 0; j < s.size(); j++) {
				int flag = 0;
				for (int k = 0; k < cnt; k++) {
					if (s[j] == c[k]) {
						a[i][j] = k, flag = 1;
						break;
					}
				}
				if (!flag) a[i][j] = cnt, c[cnt++] = s[j];
			}
			if(l[i] > 1) zero[a[i][l[i] - 1]] = 0;
			for (int j = 0; j < l[i]; j++) x[a[i][j]] += power[j] * (i + 1 == n ? -1 : 1);
		}
		cout << solve(0, 0) << endl;
	}
}