// AOJ 1161: Verbal Arithmetic
// 2018.1.9 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n, m, sz;
char str[13][11]; int len[13];
char tr[128];
char assign[10], not0[10];
char used[10];
int ans;

void calc()
{
	int i, j, s, a, c;
	char *p;

	s = 0;
	for (i = 0; i < m; i++) {
		a = 0, p = str[i]; j = len[i];
		while (j--) {
			c = assign[tr[*p++]];
			a = (a<<3) + (a<<1) + c++;
		}
		s += a;
//printf("[%d], a %d, s %d\n", i, a, s);
	}

	a = 0, p = str[m]; j = len[m];
	while (j--) {
		c = assign[tr[*p++]];
		a = (a<<3) + (a<<1) + c++;
	}
//printf("[%d], a %d, s %d\n", i, a, s);
//exit(1);
	if (a == s) ans++;
}

void rec(int k)
{
	int i;

	if (k == sz) { calc(); return; }
	if (!used[0]) {
		if (!not0[k]) {
			used[0] = 1, assign[k] = 0, rec(k+1), used[0] = 0;
		}
	}
	for (i = 1; i < 10; i++) {
		if (used[i]) continue;
		used[i] = 1, assign[k] = i, rec(k+1), used[i] = 0;
	}
}

int main()
{
	int i;
	char buf[10], *p;

	while (fgets(buf, 10, stdin) && *buf != '0') {
		sz = 0, memset(tr, -1, sizeof(tr));
		memset(not0, 0, sizeof(not0));
		n = atoi(buf), m = n - 1;
		for (i = 0; i < n; i++) {
			fgets(str[i], 15, stdin);
			for (p = str[i]; *p > ' '; p++) {
				if (tr[*p] < 0) tr[*p] = sz++;
			}
			*p = 0, len[i] = p-str[i];
			if (len[i] > 1) not0[tr[*str[i]]] = 1;
		}
		ans = 0;
		memset(used, 0, sizeof(used));
		rec(0);
		printf("%d\n", ans);
	}
	return 0;
}
