#include <bits/stdc++.h>
using namespace std;
char str[11][7];
int used[11];
int p[6][6];
int solve(int a) {
  if (a == 10) {
    for (int i = 0; i < 5; i++)
      for (int j = 0; j < 5; j++)
        if (!p[i][j]) return 0;
    return 1;
  }
  int ret = 0;
  for (int i = 0; i < 10; i++) {
    if (used[i]) continue;
    used[i] = 1;
    bool ok = true;
    if (a % 2) {
      for (int j = 0; j < 5; j++) {
        p[a / 2][j] += str[i][j] - '0';
        if (p[a / 2][j] == 2) ok = false;
      }
    } else {
      for (int j = 0; j < 5; j++) {
        p[j][a / 2] += str[i][j] - '0';
        if (p[j][a / 2] == 2) ok = false;
      }
    }
    if (ok) ret += solve(a + 1);
    used[i] = 0;
    if (a % 2) {
      for (int j = 0; j < 5; j++) {
        p[a / 2][j] -= str[i][j] - '0';
      }
    } else {
      for (int j = 0; j < 5; j++) {
        p[j][a / 2] -= str[i][j] - '0';
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    if (used[i]) continue;
    used[i] = 1;
    bool ok = true;
    if (a % 2) {
      for (int j = 0; j < 5; j++) {
        p[a / 2][j] += str[i][4 - j] - '0';
        if (p[a / 2][j] == 2) ok = false;
      }
    } else {
      for (int j = 0; j < 5; j++) {
        p[j][a / 2] += str[i][4 - j] - '0';
        if (p[j][a / 2] == 2) ok = false;
      }
    }
    if (ok) ret += solve(a + 1);
    used[i] = 0;
    if (a % 2) {
      for (int j = 0; j < 5; j++) {
        p[a / 2][j] -= str[i][4 - j] - '0';
      }
    } else {
      for (int j = 0; j < 5; j++) {
        p[j][a / 2] -= str[i][4 - j] - '0';
      }
    }
  }
  return ret;
}
int main() {
  while (1) {
    for (int i = 0; i < 5; i++)
      for (int j = 0; j < 5; j++) p[i][j] = 0;
    scanf("%s", str[0]);
    for (int i = 0; i < 10; i++) used[i] = 0;
    if (str[0][0] == 'E') break;
    for (int i = 1; i < 10; i++) scanf("%s", str[i]);
    int ret = solve(0);
    printf("%d\n", ret / 64);
  }
}
