#include <bits/stdc++.h>
using namespace std;
int res;
string s[10], srev[10];
string H[5], W[5];
bool valid(int idx) {
  for (int i = 0; i < 5; i++) {
    if (W[idx][i] == H[i][idx]) {
      return false;
    }
  }
  return true;
}
void solve(int idx, int S) {
  if (S == (1 << 10) - 1) {
    res++;
    return;
  }
  for (int i = 0; i < 10; i++) {
    if ((S >> i) & 1) continue;
    if (idx < 5) {
      H[idx] = s[i];
      solve(idx + 1, S | (1 << i));
      H[idx] = srev[i];
      solve(idx + 1, S | (1 << i));
    } else {
      W[idx - 5] = s[i];
      if (valid(idx - 5)) {
        solve(idx + 1, S | (1 << i));
      }
      W[idx - 5] = srev[i];
      if (valid(idx - 5)) {
        solve(idx + 1, S | (1 << i));
      }
    }
  }
}
int main() {
  while (cin >> s[0], s[0] != "END") {
    string tmp = s[0];
    reverse(tmp.begin(), tmp.end());
    srev[0] = tmp;
    for (int i = 0; i < 9; i++) {
      cin >> s[i + 1];
      tmp = s[i + 1];
      reverse(tmp.begin(), tmp.end());
      srev[i + 1] = tmp;
    }
    res = 0;
    solve(0, 0);
    cout << res / 64 << endl;
  }
  return 0;
}
