#include <bits/stdc++.h>
using namespace std;
int ans;
string s[10], r[10];
string t1[5], t2[5];
bool b[11];
bool check(int p) {
  for (int i = 0; i < 5; i++)
    if (t1[i][p] == t2[p][i]) return 0;
  return 1;
}
void dfs2(int d) {
  if (d == 5)
    ans++;
  else {
    for (int i = 0; i < 10; i++)
      if (!b[i]) {
        b[i] = 1;
        t2[d] = s[i];
        if (check(d)) dfs2(d + 1);
        t2[d] = r[i];
        if (check(d)) dfs2(d + 1);
        b[i] = 0;
      }
  }
}
void dfs(int d) {
  if (d == 5)
    dfs2(0);
  else {
    for (int i = 0; i < 10; i++)
      if (!b[i]) {
        b[i] = 1;
        t1[d] = s[i];
        dfs(d + 1);
        t1[d] = r[i];
        dfs(d + 1);
        b[i] = 0;
      }
  }
}
int main() {
  while (cin >> s[0], s[0] != "END") {
    memset(b, 0, sizeof(b));
    ans = 0;
    r[0] = s[0];
    reverse(r[0].begin(), r[0].end());
    for (int i = 0; i < 9; i++) {
      cin >> s[i + 1];
      r[i + 1] = s[i + 1];
      reverse(r[i + 1].begin(), r[i + 1].end());
    }
    int p = 0;
    for (int i = 0; i < 10; i++)
      if (s[i] == r[i]) p++;
    dfs(0);
    cout << ans << endl;
  }
}
