#include <bits/stdc++.h>
using namespace std;
int in() {
  int x;
  cin >> x;
  return x;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (1) {
    int n;
    cin >> n;
    if (n == 0) break;
    int u[30] = {}, mem[30] = {}, zeros[30] = {};
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      int d = 1;
      for (int j = s.size() - 1; j >= 0; j--) {
        if (i != n - 1) u[(s[j] - 'A')] += d;
        if (i == n - 1) {
          u[(s[j] - 'A')] -= d;
          if (u[(s[j] - 'A')] == 0) mem[(s[j] - 'A')] = 1;
        }
        d *= 10;
        if (j == 0 && s.size() > 1) zeros[(s[j] - 'A')] = 1;
      }
    }
    for (int i = 0; i < 26; i++) {
      if (u[i] != 0) mem[i] = 1;
    }
    int y[30] = {}, zero[30] = {};
    int k = 0;
    for (int i = 0; i < 26; i++) {
      if (mem[i]) {
        y[k] = u[i];
        zero[k++] = zeros[i];
      }
    }
    int ans = 0;
    vector<int> f;
    vector<int> pre;
    for (int i = 1; i <= 9; i++) f.push_back(i);
    int yy = k + 1;
    if (yy > 10) yy = 10;
    for (int j = 0; j < yy; j++) {
      do {
        if (j < k && zero[j]) continue;
        vector<int> check;
        if (j != k) {
          for (int i = 0; i < k - 1; i++) {
            if (i == j) {
              check.push_back(0);
            }
            check.push_back(f[i]);
          }
          if (k - 1 == j) check.push_back(0);
        } else {
          for (int i = 0; i < k; i++) check.push_back(f[i]);
        }
        if (pre == check) continue;
        int temp = 0;
        for (int i = 0; i < k; i++) {
          temp += check[i] * y[i];
        }
        if (temp == 0) {
          ans++;
        }
        pre = check;
      } while (next_permutation(f.begin(), f.end()));
      for (int i = 0; i < 9; i++) f[i] = i + 1;
      pre = vector<int>(1);
    }
    cout << ans << endl;
  }
}
