#include <bits/stdc++.h>
const int INF = 100000000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std;
string board[10];
bool ok(vector<string> &tate, vector<string> &yoko) {
  for (int i = 0; i < (tate.size()); i++)
    for (int j = 0; j < (tate[i].size()); j++)
      if (tate[i][j] == yoko[j][i]) return false;
  return true;
}
void show(vector<string> &tate, vector<string> &yoko) {
  for (int i = 0; i < (tate.size()); i++) {
    cout << tate[i] << endl;
    ;
  }
  cout << endl;
  for (int i = 0; i < (5); i++) {
    for (int j = 0; j < (5); j++) cout << yoko[j][i];
    cout << endl;
  }
  cout << endl;
  cout << endl;
}
void solve() {
  int ans = 0;
  sort(board, board + 10);
  do {
    vector<string> tate, yoko;
    for (int i = 0; i < (5); i++) tate.push_back(board[i]);
    for (int i = 0; i < (5); i++) yoko.push_back(board[5 + i]);
    for (int S1 = 0; S1 < (1 << 5); S1++) {
      for (int i = 0; i < (5); i++)
        if (S1 >> i & 1) reverse((tate[i]).begin(), (tate[i]).end());
      for (int S2 = 0; S2 < (1 << 5); S2++) {
        for (int i = 0; i < (5); i++)
          if (S2 >> i & 1) reverse((yoko[i]).begin(), (yoko[i]).end());
        if (ok(tate, yoko)) ans++;
        for (int i = 0; i < (5); i++)
          if (S2 >> i & 1) reverse((yoko[i]).begin(), (yoko[i]).end());
      }
      for (int i = 0; i < (5); i++)
        if (S1 >> i & 1) reverse((tate[i]).begin(), (tate[i]).end());
    }
  } while (next_permutation(board, board + 10));
  cout << ans / 64 << endl;
}
int main() {
  while (1) {
    cin >> board[0];
    if (board[0] == "END") break;
    for (int i = 0; i < (9); i++) cin >> board[i + 1];
    solve();
  }
  return 0;
}
