#include <bits/stdc++.h>
using namespace std;
vector<string> vec, hvec;
int res;
bool used[10];
map<string, bool> mpp;
void mkMap(vector<string> v) {
  string s1, s2, s3, s4, str;
  s1 = s2 = s3 = s4 = "";
  for (int i = 0; i < 5; ++i) {
    str = v[i];
    s1 += str;
    s3 = str + s3;
    reverse(str.begin(), str.end());
    s2 += str;
    for (int j = 0; j < 5; ++j) {
      s4 += ((v[j][i] == '1') ? "0" : "1");
    }
  }
  mpp[s1] = mpp[s2] = mpp[s3] = mpp[s4] = true;
  return;
}
bool check(string str, int p) {
  for (int i = 0; i < 5; ++i)
    if (hvec[i][p] == str[i]) return false;
  return true;
}
bool check2(vector<string> v) {
  string s1 = "";
  for (int i = 0; i < 5; ++i) s1 += v[i];
  if (mpp[s1]) return false;
  mkMap(v);
  return true;
}
void func3(vector<string> v1, int p) {
  if (p == 10) {
    res++;
    mkMap(v1);
    return;
  }
  string str;
  vector<string> v2;
  for (int i = 0; i < 10; ++i)
    if (used[i]) {
      used[i] = false;
      str = vec[i];
      if (check(str, p - 5)) {
        v2 = v1;
        v2.push_back(str);
        func3(v2, p + 1);
      }
      reverse(str.begin(), str.end());
      if (str != vec[i] && check(str, p - 5)) {
        v2 = v1;
        v2.push_back(str);
        func3(v2, p + 1);
      }
      used[i] = true;
    }
  return;
}
void func4(vector<int> v) {
  string str;
  for (int i = 0; i < 5; ++i) {
    str = vec[v[i]];
    if (!check(str, i)) return;
    reverse(str.begin(), str.end());
    if (str == vec[v[i]] || !check(str, i)) return;
  }
  res++;
  return;
}
void func2(vector<int> v, vector<string> v1, int p) {
  if (p == 5) {
    res++;
    mkMap(v1);
    return;
  }
  string str = vec[v[p]];
  vector<string> v2;
  if (check(str, p)) {
    v2 = v1;
    v2.push_back(str);
    func2(v, v2, p + 1);
  }
  reverse(str.begin(), str.end());
  if (str != vec[v[p]] && check(str, p)) {
    v2 = v1;
    v2.push_back(str);
    func2(v, v2, p + 1);
  }
  return;
}
void func(vector<string> v1, int p) {
  vector<string> v2;
  if (p == 5) {
    hvec = v1;
    if (check2(hvec)) {
      func3(v2, p);
    }
    return;
  }
  string str;
  for (int i = 0; i < 10; ++i)
    if (used[i]) {
      used[i] = false;
      str = vec[i];
      v2 = v1;
      v2.push_back(str);
      func(v2, p + 1);
      reverse(str.begin(), str.end());
      v2 = v1;
      v2.push_back(str);
      if (str != vec[i]) func(v2, p + 1);
      used[i] = true;
    }
  return;
}
int main() {
  vector<string> v;
  string str;
  while (cin >> str && str != "END") {
    vec.push_back(str);
    res = 0;
    for (int i = 0; i < 9; ++i) {
      cin >> str;
      vec.push_back(str);
    }
    fill(used, used + 10, true);
    func(v, 0);
    cout << res / 2 << endl;
    vec.clear();
    mpp.clear();
  }
  return 0;
}
