#include<iostream>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<cmath>
#define P pair<int ,int>
#define N 10
using namespace std;

bool n_zero[N], f[N];
int coe[N], cnt, c;

void dfs(int n, int s) {
	if (n == cnt) {
		if (!s) c++;
		return;
	}
	
	for (int i = 0; i < N; i++) {
		if (f[i] || (!i && n_zero[n])) continue;
		
		f[i] = 1;
		dfs(n + 1, s + i * coe[n]); 
		f[i] = 0;
	}
	
}

int main()
{	
	int n;
	
	while (cin >> n, n) {
		vector<string> str(n);
		map<char, int> index;
		cnt = c = 0;
		
		for (int i = 0; i < N; i++)
			n_zero[i] = coe[i] = f[i] = 0;
		
		for (int i = 0; i < n; i++) {
			cin >> str[i];
			
			for (int j = 0; j < str[i].size(); j++) {
				if (index.find(str[i][j]) == index.end()) {
					index[str[i][j]] = cnt;
					cnt++;
				}
				
				if ( str[i].size() > 1 && !j) n_zero[index[str[i][j]]] = 1;
				
				if (i != n - 1)
					coe[index[str[i][j]]] += (int)pow(10.0, (int)str[i].size() - 1 - j);
				else
					coe[index[str[i][j]]] -= (int)pow(10.0, (int)str[i].size() - 1 - j);
			}
		}
		
		dfs(0, 0);
		
		cout << c << endl;
	}
	
	return 0;
}