#include <bits/stdc++.h>
using namespace std;
int calc(vector<int> &ver, vector<int> &hor, string &vs) {
  bool used[5];
  memset(used, false, sizeof(used));
  for (int i = 0; i < 5; i++) {
    bool flag = false;
    int bit = 0;
    for (int j = 0; j < 5; j++) {
      if (ver[j] & (1 << i)) bit += (1 << j);
    }
    for (int j = 0; j < 5; j++) {
      if (bit == hor[j] && used[j] == false) {
        flag = true;
        used[j] = true;
      }
    }
    bit = ((~bit) & 31);
    for (int j = 0; j < 5; j++) {
      if (bit == hor[j] && used[j] == false) {
        flag = true;
        used[j] = true;
      }
    }
    if (flag == false) return 0;
  }
  return 1;
}
int dfs(vector<int> &ver, vector<int> &hor) {
  int res = 0;
  string vs = "12345";
  do {
    for (int i = 0; i < (1 << 5); i++) {
      vector<int> tmp(ver.size(), 0);
      for (int j = 0; j < 5; j++) {
        if (i & (1 << j)) {
          for (int k = 0; k < 10; k++) {
            if ((ver[j] & (1 << k))) tmp[j] += (1 << (9 - k));
          }
        }
      }
      res += calc(tmp, hor, vs);
    }
  } while (next_permutation(vs.begin(), vs.end()));
  return res;
}
int main(int argc, char *argv[]) {
  string s;
  vector<int> board(10, 0);
  while (1) {
    std::cin >> s;
    vector<string> bit;
    if (s == "END") break;
    bit.push_back(s);
    for (int i = 0; i < 9; i++) {
      std::cin >> s;
      bit.push_back(s);
    }
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < bit[i].length(); j++) {
        if (bit[i][j] == '1') board[i] += (1 << (bit[i].length() - j - 1));
      }
    }
    long long int ans = 0;
    for (int i = 0; i < (1 << 10); i++) {
      if (__builtin_popcount(i) != 5) continue;
      vector<int> ver, hor;
      for (int j = 0; j < 10; j++) {
        if (i & (1 << j))
          ver.push_back(board[j]);
        else
          hor.push_back(board[j]);
      }
      ans += dfs(ver, hor);
    }
    std::cout << ans / 4 << std::endl;
  }
  return 0;
}
